数据访问层(DAL)设计
我正在使用 .Net 企业库数据访问应用程序块进行数据访问层设计。
在我的 Category DAL 类中,我有这样的方法:
GetProductsInCategory(int CatId)、GetAllProducts、GetCategories 等。
我的问题是:我应该把这行代码放在哪里?
DatabaseFactory.CreateDatabase("MyDB");
我应该将它放在上面的每个方法中,还是应该有一个基类将数据库对象返回到我的 DAL 类。
另外,我应该将这些 DAL 类方法保留为静态吗?
I'm using .Net enterprise library data access application block for my Data Access layer design.
In my Category DAL class, I've methods like :
GetProductsInCategory(int CatId), GetAllProducts, GetCategories, etc.
My question is: where do I put this line of code ?
DatabaseFactory.CreateDatabase("MyDB");
shall I put it in every method above or shall I have a base class which would return Database object to my DAL class.
Also, shall I keep these DAL class methods as static?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我更喜欢返回常见对象(例如连接)的基类,在您的示例数据库中。
以下是设计数据访问层的参考:.NET 应用程序架构:数据访问层
我使用 Microsoft Enterprise Library 数据访问应用程序块。 它完成了这里提到的大部分事情。 但像连接或交易这样的常见内容会转到我的基类。
I prefer a base class that returns common objects like connection, in you example Database.
Here is reference to desing Data access Layer : .NET Application Architecture: the Data Access Layer
I use Microsoft Enterprise Library Data Access Application Block. It does most of the things mentioned here. but common stuff like connections or transactions goes to my base class.
感谢您的提示..我将拥有从基类 DBManager 派生的所有 DAL 类。该类将有一个名为 GetDatabase() 的受保护方法,该方法将包含代码: return DatabaseFactory.CreateDatabase("MyDB"); 我在派生类中的方法如下所示:..
这个 DAL 设计看起来还好吗?
thanks for ur tips..i will have all my DAL classes derived from a base class DBManager.This class will have a protected method called GetDatabase() which will have code: return DatabaseFactory.CreateDatabase("MyDB"); And my method in derived class would look like:..
does this DAL design look ok?
我建议考虑使用 SubSonic 进行 DAL 和对象生成。 它实现了 Microsoft 的应用程序块,但为您提供了简单(且强大)的查询功能,例如;
当然,它实现了 ActiveRecord 模式,因此对象类具有 .Delete()、. Add()、.Get() 类型方法。
I would suggest looking at using SubSonic for DAL and object generation. It implements Microsoft's Application Block but gives you simple (and robust) query capabilites like;
And of course it implements the ActiveRecord pattern so the object classes have the .Delete(), .Add(), .Get() type methods.