views:

304

answers:

2

This is concerning an enterprise application with a very generic database (all objects are identified using data in the database and internationalized/globalized/localized).

  • Make a model for Repository pattern, then make (generate 1:1) another model for DB access (LINQ2SQL or EF) and use the later as repository model data access layer?
  • Just use L2S/EF/NHibernate model directly, mapping model to DB and opening persistence layer?

Will this dual model idea (repository pattern) popup problems making dynamic stackable LINQ search queries possible when using L2S/EF model directly in a dual model environment?

Please advise.

A: 

As long as you are exposing IQueryable objects in your repository, you should have no problem stacking queries in the manner you suggest.

I would be cautious about using Entity Framework for this, since lazy loading is not supported in the way you might expect. Linq to SQL will handle lazy loading without problems.

For more information about lazy loading in the Entity Framework, see:
http://www.singingeels.com/Articles/Entity_Framework_and_Lazy_Loading.aspx

Robert Harvey
I am aware of EF advantages and disadvantages as I've been researching it and writing articles on it. I'm mentioning EF as in a solution where EF would be a working model for the business logic.
BuzzBubba
In my opinion, you should create a separate layer for the business logic, unless EF has built-in hooks for that.
Robert Harvey
So, you think I should make a model for all my business objects with model-first approach, then use EF designer to generate a new model and link the two trough methods of classes of the business model?-e.g. like "Account" and "Accounts" classes and "EFAccount" (EF generated entity matching table "TAccount") where Accounts would have a method GetAccount(int id) which returns "Account", but internally it constructs "Account" using auto-generated "EFAccount" and some of it's properties trough a LINQ query?-(I hope I'm clear enough here)
BuzzBubba
This way, in theory, I should be able to separate Account implementation and it's methods' implementations for use with different DALs like EF, L2S, NHib etc. which I could write a special "provider" classes defining actual classes for business objects interfaces (IAccounts implementations which use Account business object)?
BuzzBubba
I think I have a sense of what you are trying to do. It sounds interesting.
Robert Harvey
But what is the best practices suggestion? I'm kinda low on time to experiment and rewrite the whole project when I hit the brick wall:P
BuzzBubba
As long as you have a layer of abstraction between your DAL and the rest of your program, you should have no trouble swapping the DAL out, if that's what you're after.
Robert Harvey
Don't use EF at all. Its a dog, and its not ready for the enterprise. Use NHibernate if possible.
scope_creep
@scope: I assume you are referring to EF 4.0?
Robert Harvey
Yip. Also I think Linq to Sql is not going forward, just bug fixes, its dead.
scope_creep
@scope: *sigh* That old argument again. Linq to SQL is part of the .NET Framework. Saying it is dead is like saying the Framework is dead.
Robert Harvey
@scope: Linq to SQL got [several fixes and enhancements](http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40) in .NET 4.0.
Robert Harvey
A: 

Take a look at sharp architecture.

Regarding returning IQueryable from your repository objects, it is my opinion that doing such blurs a proper separation of concerns in your application. I'm all for working with IQueryable within your data access layer but once you start returning objects as IQueryable you provide the opportunity for your controllers and/or views to start meddling with data access. Such may even negatively impact the testability of your application as well.

wgpubs
I understand the concern.
BuzzBubba