[英]C# Design How to Elegantly wrap a DAL class
I have an application which uses MyGeneration's dOODads ORM to generate it's Data Access Layer. 我有一个使用MyGeneration的dOODads ORM生成其数据访问层的应用程序。 dOODad works by generating a persistance class for each table in the database.
dOODad通过为数据库中的每个表生成一个持久性类来工作。 It works like so:
它的工作原理如下:
// Load and Save
Employees emps = new Employees();
if(emps.LoadByPrimaryKey(42))
{
emps.LastName = "Just Got Married";
emps.Save();
}
// Add a new record
Employees emps = new Employees();
emps.AddNew();
emps.FirstName = "Mr.";
emps.LastName = "dOOdad";
emps.Save();
// After save the identity column is already here for me.
int i = emps.EmployeeID;
// Dynamic Query - All Employees with 'A' in thier last name
Employees emps = new Employees();
emps.Where.LastName.Value = "%A%";
emps.Where.LastName.Operator = WhereParameter.Operand.Like;
emps.Query.Load();
For the above example(ie Employees DAL object) I would like to know what is the best method/technique to abstract some of the implementation details on my classes. 对于上面的示例(即,雇员DAL对象),我想知道什么是在类上抽象一些实现细节的最佳方法/技术。 I don't believe that an Employee class should have Employees(the DAL) specifics in its methods - or perhaps this is acceptable?
我认为Employee类的方法中不应包含Employees(DAL)细节,或者这是否可以接受? Is it possible to implement some form of repository pattern?
是否可以实现某种形式的存储库模式? Bear in mind that this is a high volume, perfomacne critical application.
请记住,这是大量的性能关键的应用程序。
Thanks, j 谢谢,j
try coming up with an interface with methods you would want to be exposed by your DAL. 尝试提出一个接口,该接口带有您希望DAL公开的方法。 Have your client code bind to the interface.
将您的客户端代码绑定到该接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.