简体   繁体   中英

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. 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(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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM