ASP.NET MVC2 Data Access Layer

For a small / medium sized project I am trying to figure out what is the "ideal" way to have a domain level and a data access layer. My opinion on association tends to be more about the opinion that domain models should not be tightly coupled to the database layer, in other words, the data access layer should not actually know anything about domain objects.

I was looking at Linq-to-sql and it wants to use its own models that it creates and so it ends up very tightly. While I like the way you use linq-to-sql in your code, I really don't like the way it wants to create its own domain objects.

What are some alternatives that I should consider? I tried using NHibernate, but I didn't like how I was supposed to use to query and get different objects. I sincerely love the syntax and way of using linq, I just don't want it to be so tightly coupled with domain objects.

+2


a source to share


4 answers


If you don't want your domain to be tightly coupled to your database, your options are pretty much:

  • NHibernate
  • Entity Framework


Linq 2 Sql since you found yourself generating code from your database layer, so out of the question. The same goes for Subsonic and LLBLGen Pro (I believe correct me if I'm wrong). Entity Framework also fell into that boat, but version 4 comes with "first code" support, so it is definitely an option.

Both NHibernate and Entity Framework support LINQ queries, although LINQ support for LINQ is presumably superior to NHibernate support. I agree that HQL queries and Criteria are not as elegant as LINQ, but I feel that NHibernate LINQ support will be greatly improved from 3.0.

+3


a source


I've posted an answer to a similar question that might help. I could repeat the whole thing here, but I thought I'd just point you to the answer there, as I suggest using the same type of repository to separate your data.



MVC + repository pattern - still data model dependent?

0


a source


You can use LINQ to SQL to create types that represent data entities. These are pretty simple classes that represent tables in your database. In an MVC project, you have to use them to feed data to the business layer, from which you can start defining business objects and then (and very importantly, in my opinion) define your presentation model.

0


a source


I know you don't really like NHibernate, but if you want to give it a second look take a look at http://sharparchitecture.net/ . They are really in the business of developing a project template, while at the same time separating attention.

0


a source







All Articles