Data Access Layer design patterns

后端 未结 7 1271
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 06:38

I have to design a Data Access Layer with .NET that probably will use more than one database management system (Mysql and Sql Server) with the same relational design.

<
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 07:30

    It really depends on the size of your layer and the type of product your developing. If it is fairly well contained then ADO.NET will probably be ideal. If it is a bigger DAL layer, and its greenfield development of multitargeted dbms it's best to use an ORM tool. They are fast, efficient and mature products, and can quickly enable the retargetting to another db, simply by changing a single parameter. Writing static ADO, is something that is passing into legacy.

    There are several ORM tools which can do the job, all work slightlty differently, and depend on your budget, size of your team etc. They can either work by having to write a mapping class like NHibernate, or work through reflection, i.e attribute markup.

    For free, i.e. open source, if your skint, NHibernate is ideal. I'm using this at the moment, to build the DAL layer, for a large enteprise product. Its excellent, but take some time to master. With NHibernate you define mapping classes, which when executed generate the db model for you. It supports stored procedures. The downside is that it takes some time to learn, especially around mapping complex data correctly. Its excellent. It has a huge bundle of samples and other projects floating about thats used it. Check out Koders.com.

    If you have a some budget, then LLBLGen is ideal. It is strongly typed and also supports stored procedures.

    If have some of the data model already available, then TierDeveloper is ideal. Its essentially free, and works by developing a set of classes from your database model. The only downside is the mapper for mysql is 3rd party. It is a enteprise class product that has been made free to support ncache, and its a possible approach.

    If you are desperate to stick with MS, they are moving towards ORM, and have a product called ADO.NET Entity Framework. Functionally it is not as complete as the tools defined above. Its about 3 generations behind in maturity. Its available in vs 2008 sp1. The connector for mysql would be a cost.

    Also, you could use LINQ. It will also target mysql, if you would also need the connector.

    Ideally, your best bet is with ORM. If you can't support open source, and have budget, then get

    Hope that helps.

提交回复
热议问题