开发者

C# Design How to Elegantly wrap a DAL class

开发者 https://www.devze.com 2022-12-28 11:38 出处:网络
I have an application which uses MyGeneration\'s dOODads ORM to generate it\'s Data Access Layer. dOODad works by generating a persistance class for each table in the database. It works like so:

I have an application which uses MyGeneration's dOODads ORM to generate it's Data Access Layer. dOODad works by generating a persistance class for each table in the database. 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(i.e. Employees DAL object) I would like to know what is the best method/technique to abstract some of the implementation details on my classes. I don't believe that an Employee class should have Employees(the DAL) specifics in its methods - or perhaps this is acceptable? Is it possible to implement some form of repository pattern? Bear in mind that this is a high volume, perfomacne critical application.

Thanks, j


try coming up with an interface with methods you would want to be exposed by your DAL. Have your client code bind to the interface.

0

精彩评论

暂无评论...
验证码 换一张
取 消