简体   繁体   English

.net中的数据访问层

[英]Data Access Layer in .net

I am designing an application where I want to reduce the burden on the developers for future for development. 我正在设计一个应用程序,希望减轻开发人员将来的开发负担。 In this I have list of classes eg-"User,Account,Permission and etc" now these classes are associated to the table in the database with the name of the class same as data table. 在这里,我有一个类列表,例如“ User,Account,Permission等”,现在这些类与数据库中的表相关联,并且其类名与数据表相同。 I want my business layer to be robust so that in future whenever I add any more column to the data table I don't have to rewrite insert update and delete command just adding property to the class should do the job. 我希望我的业务层能够保持健壮,以便将来每当我向数据表中添加更多列时,都不必重写insert update和delete命令,而只需向类添加属性即可。

Any Idea how to do this? 任何想法如何做到这一点?

What you are looking for is probably an ORM (Object-Relational Mapping) framework. 您正在寻找的可能是一个ORM(对象关系映射)框架。 The most popular ones for .NET includes Linq-to-SQL (or Entity Framework), NHibernate nad ActiveRecord. .NET最受欢迎的工具包括Linq-to-SQL(或实体框架),NHibernate和ActiveRecord。 Using an ORM is considered a best practice for achieving a maintainable and robust Data Access Layer. 使用ORM被认为是实现可维护且强大的数据访问层的最佳实践。

See a list of frameworks here . 在此处查看框架列表

What you're probably looking for is to implement an Object Relational Mapping (ORM) solution. 您可能正在寻找的是实现对象关系映射 (ORM)解决方案。 Many ORM solutions help you maintain table and entity definitions and also create the appropriate queries for you. 许多ORM解决方案都可以帮助您维护表和实体定义,还可以为您创建适当的查询。

Popular ORMs for the .Net Framework include NHibernate, the ADO Entity Framework and LINQ to SQL. .Net Framework的流行ORM包括NHibernate,ADO Entity Framework和LINQ to SQL。 Otherwise you could consider mapping your data model using templates (like using Codesmith, or the Net Tiers templates). 否则,您可以考虑使用模板(例如使用Codesmith或Net Tiers模板)映射数据模型。

You could check out the answers to this question for more advice on picking an ORM solution , or you can just browse some ORM related questions tagged here . 您可以查看该问题的答案,以获取有关选择ORM解决方案的更多建议,也可以浏览此处标记的一些与ORM相关的问题

I think what you are looking for is a Data Transfer Object . 我认为您正在寻找的是数据传输对象 Here's an article that explains more about the DTO pattern. 这是一篇介绍DTO模式的文章

Additionally, here's an article that explains how to implement a DTO with a Dataset. 此外, 本文还介绍了如何使用数据集实现DTO。 In your case, the Dataset would be replaced with your own Datalayer. 在您的情况下,数据集将替换为您自己的数据层。

Picking an ORM solution is one way, additionally i would mention the upcoming Oslo . 选择ORM解决方案是一种方法,此外,我还要提到即将到来的Oslo

For a more "traditional" approach i would take a look of Data Abstract . 对于更“传统”的方法,我将看一下Data Abstract

Quite interesting reading about this topic is the Persitence Patterns article . 关于此主题的非常有趣的阅读是Persitence Patterns文章 It explains the most common and basic design patterns used for the Data Access. 它说明了用于数据访问的最常见和基本的设计模式。 Also it discusses when the concrete DP might be more suitable than the other. 它还讨论了具体的DP何时可能比另一个更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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