For a small/medium sized project I’m trying to figure out what is the ‘ideal’ way to have a domain layer and data access layer. My opinions on coupling tend to be more towards the view that the domain models should not be tightly coupled with the database layer, in other words the data access layer shouldn’t actually know anything about the domain objects.
I’ve been looking at Linq-to-sql and it wants to use its own models that it creates, and so it ends up VERY tightly coupled. Whilst I love the way you use linq-to-sql in code I really don’t like the way it wants to make its own domain objects.
What are some alternatives that I should consider? I tried use NHibernate but I did not like the way I had to use to query and get different objects. I honestly love the syntax and way you use linq, I just don’t want it to be so tightly coupled to domain objects.
If you don’t want your domain to be tightly coupled to your database, then your choices are pretty much:
Linq 2 Sql as you’ve discovered generates code from your database layer, so that’s out of the question. Same goes for Subsonic and LLBLGen Pro (I believe, correct me if I’m wrong). Entity Framework used to fall into this boat as well, but version 4 has shipped with “code first” support so it’s definitely an option.
Both NHibernate and Entity Framework support LINQ queries, although Entity Framework’s LINQ support is supposedly superior to that of NHibernate’s. I agree that HQL and Criteria queries are not nearly as elegant as LINQ, but I have a feeling NHibernate’s LINQ support will be vastly improved come version 3.0.