使用属性和反射过渡从数据存取层到业务物件 - III

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

简介本系列的最后一篇文章.第一部分如何描述,二部分如何取得描述.现在我们就要创建DAL库来使我们的标题可行.

设计DAL库我想创建的类库支持Sqlserver 和oledb.我把库分成了以下的部分:

Utility classesclass DALQueryBuilder生成sql语句更新物件.

class DALParameter生成参数保存在存储过程中.

class DALException继承于System.Exception , 数据库有异常时将会提供更多的信息.

Attribute classes参见第一篇.

DAL 本身class DALEngine这个抽象的类用于数据库操作,是数据库程序更加简单.它的虚拟和抽象的方法有不同的实施.

class DALSqlEngine

class DALOleDbEngine耧一眼DALEngine 类public

{

IDbConnection conn = = ArrayList parameters =

//

CommandBehavior behavior);

CommandBehavior behavior);

Type childType);

}

public

{

{

}

{

ArrayList result =

RetrieveChildObjects(customer.Id, result,

}

{

UpdateObjects(customer.Dependents);

}

}

看个例子:

public

{

DAL dal =

{

Contact contact =

contact.Name = ;

contact.Age = contact.Address = ;

contact.Address2 = contact.PostalCode = contact.City = ;

contact.State = contact.Country =

dal.UpdateObject(contact);

Console.WriteLine(contact);

Contact joaoCardoso = (Contact)dal.RetrieveObject( joaoCardoso.Age++;

Console.WriteLine(joaoCardoso);

Console.WriteLine(

Customer customer =

customer.Name = ;

customer.Age = customer.Address = ;

customer.Address2 = customer.PostalCode = customer.City = ;

customer.State = customer.Country = ;

customer.TotalPurchased += customer.NumberOfPurchases++;

dal.UpdateObject(customer);

Customer paul = (Customer)dal.RetrieveObject( Console.WriteLine(paul);

paul.TotalPurchased += 100M;

paul.NumberOfPurchases++;

dal.UpdateObject(paul);

{

CustomerDependent dependent = paul.NewDependent();

dependent.Name = ;

dependent.Age = paul.Dependents.Add(dependent);

dependent = paul.NewDependent();

dependent.Name = ;

dependent.Age = paul.Dependents.Add(dependent);

dependent = paul.NewDependent();

dependent.Name = ;

dependent.Age = dependent.Relationship = CustomerRelationship.Friend;

paul.Dependents.Add(dependent);

dal.UpdateCustomerDependents(paul);

}

{

Console.WriteLine(, paul.Name);

{

Console.WriteLine(, dependent.Id,

dependent.Name, dependent.Relationship);

dependent.Relationship = CustomerRelationship.Family;

}

dal.UpdateCustomerDependents(paul);

}

}

{

dal.Dispose();

}

}

Conclusion有老多局限性,需要我们去进一步实施思考,但是你理解了这些以后,我们就可以进行nhibernate的理解研究和应用了,祝你好运.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航