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(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.
精彩评论