• Active Record Patter, Active记录模式


    活动记录模式通常用于数据驱动应用程序中的模型数据库表或视图的类,以其模型数据库表的一行由类的实例。 在这种模式类的属性将映射到相应的数据库表的列中。

    类的实例方法上执行操作在数据库记录而其静态方法使用整个表。 是例如如果数据库包含一个名为列 EmployeeId uniqueidentifier、 作为一个 nvarchar(50) 的名称和作为一个货币的薪水的雇员的表,实现活动记录模式您想创建一个名为类 Employee 具有名为 EmployeeId、 名称和薪水的属性。 在员工类将包括实例方法如创建,保存,和删除,并可能包括如 DeleteAll、 查找和 FindAll 的静态方法。

    图 1 显示了活动记录模式。 它提供了一个简单、 直观语法使用数据并使用多个对象关系 mappers (O / RM) 模式。

      图 1 中的活动记录模式

    // Add Andrew Fuller as a new employee  
    Employee emp = new Employee();
    emp.Name = "Andrew Fuller";
    emp.Salary = 50000.00M;
    emp.Create();
    
    // Give a 10% raise to all employees 
    Employee[] allEmployees = Employee.FindAll();
    foreach (Employee current in allEmployees)
    {
        current.Salary *= 1.10M;
        current.Save();
    } 

    具体看企业应用架构模式

  • 相关阅读:
    57. Insert Interval
    287. Find the Duplicate Number
    52. N-Queens II
    51. N-Queens
    151. Reverse Words in a String
    29. Divide Two Integers
    [POJ2104]K-th Number
    [JSOI2008]最大数
    [BZOJ3673&3674]可持久化并查集&加强版
    C++ STL rope介绍----可持久化平衡树
  • 原文地址:https://www.cnblogs.com/cute/p/2690508.html
Copyright © 2020-2023  润新知