New .NET 3.5 project: which DAL technology to use?

I am preparing a new Windows project and wondering what DAL technology to use. Initially, I was looking for something simpler so as not to spend too much time creating it. But I also understand that it must be efficient and scalable in the long run.

I plan to use the WPF client (MVVM) and the WCF service on a three-tier system.

To summarize all existing technologies, I am familiar with:

Dataset

PRO: You can be a little old-fashioned, but very easy to use and allow most parts to be automatically created for you. One of the powerful aspects of a data set is the ease of passing related data through relationships. Also, in some ways, it is disconnected from the database and can simplify updates by automatically saving timestamps. Includes verification.

CONTRA: Pretty old fashioned. Some consider them not to be real business objects / models, but simply a mirror of your SQL data tables. Transferring them between WCF Service / Client can be more complicated than creating business objects.

Corporate Library 4.1 - Data Access Block

PRO: DAL fits nicely in the Factory pattern. It automatically closes and closes the connection. Very easy to use for the most part. It supports both a dataset and regular SQL Sps for creating your own business objects. Within the current Framework, it can be much more efficient to use in conjunction with the rest of the Enterprise Library for an effective end product.

CONTRA: ??

Linq to sql

PRO: Auto creates SQL tables in business objects. Easy CRUD. Theoretically, this is a very good way to do this.

CONTRA: After playing with her when she came out, I found her flaky and sometimes unstable. It is already considered dead technology after Microsoft announced that Entity Framework 4.0 - as part of .NET 4.0 - will be recommended by Microsoft. In .NET 4.0, there is too little expectation of errors, but there are no more plans for expanding features.

Entity Framework 4.0

I don't know anything about this, but only that it will eventually replace everything else, as on .NET 4.0. I am also tempted to use it, however, since it is still in BETA, I still could not go this way.

I really like to use Enterprise Library 4.1 - Data Access Block and create my own business objects. The big Con is that it takes longer to create a DAL. If someone cannot convince me to use DataSets through a data access block, instead.

What are your comments and ideas? Thank you very much kava

+7
dataset linq-to-sql enterprise-library data-access-layer
source share
5 answers

You mention the Entity Framework as part of the "contra" for the Linq to SQL parameter, but you should consider it instead of Linq to SQL - it provides almost the same functionality and more. For projects with smaller databases, it definitely gives a lot of buzz for the dollar. In EF, it can be difficult to manage the context for large databases, and schema changes can cause things to break, but these problems exist with any approach to data access.

The biggest argument for EntLib, in my opinion, is that you are still loading your own data objects. The corporate library removes a lot of plumbing code from the direct implementation of the "old school" ADO.NET, which is nice, but does not create data objects for you that can be used out of the box for LINQ queries.

+3
source share

We previously used DataSets with Application Data EntLib 4.1 block.

Now we use the Entity Framework. We have achieved significant performance improvements with the Entity Framework compared to EntLib 4.1. (Software data layer for 80 tables in 10 hours instead of 80)

Entity Framework 4 is still in beta, but if it comes some time before your project starts working, I will go with EF 4. You will get ORM performance at the same time the flexibility of using POCO (Plain Old Clr Objects)

+2
source share

but. Check also NHibernate.

C. DataSet is the fastest and easiest, but you have a lot of code.

Everything else - there are many benefits in using ORM tools, but there are many problems with 3 levels with them.

(lazy loading is a problem that one has to face when creating a large number of large object trees that affect performance; caching is not as smart as possible)

So, it depends on your basic needs and how much time you want to spend learning EL / LINQ or NHibernate before coding starts, b / c there is a learning curve using these tools.

+1
source share

It is best to be able to use both technologies at the same time. How can you do this? It is very simple with a repository template. First you need to create a common IRepository interface. Something like:

public interface IERepository<E> { DbTransaction BeginTransaction(); void EndTransaction(); void Add(E entity); void Delete(E entity); int Save(); ObjectQuery<E> DoQuery(string entitySetName); IList<E> SelectAll(string entitySetName); E SelectByKey(int Key); bool TrySameValueExist(string fieldName, object fieldValue, string key); bool TryEntity(ISpecification<E> selectSpec); int GetCount(); int GetCount(ISpecification<E> selectSpec); int AddAndSave(E entity); } 

I prefer the Entity Framework. I created 3 projects on it. It works very fast, especially with search queries. So, after you need to create a basic universal class repository with virtual methods that implements the IRepository interface. And it's all. You now have a very fast way to create simple DAl code as follows:

 public class MonthRepository:Repository<Month> { } 

You have the opportunity to override all the methods of the base class and create access to the database using the stored procedure where you need it. And you can do it without changing the code in other places. You will still return objects of the same type, but get them in a different way.

Repeat more at http://www.codeproject.com/KB/database/ImplRepositoryPatternEF.aspx

+1
source share

NHibernate has the best overall combination of feature set, maturity and support.

NHibernate, Entity Framework, Active Records, or linq2sql

You should think that Linq supports priority for any solution you think, and your first two options above do not support Linq.

+1
source share

All Articles