views:

1612

answers:

2

Hello:

Stephan Walters video on MVC and Models is a very good and light discussion of the various topics listed in this questions title. The one question listed in the notes unanswered was:

If you create an Interface / Repository pattern for Linq2SQL, does Linq2SQLs classes still cause a dependency on Linq, even though you pass the classes as toList?

It is probably an easy answer YES, however, what standard mechanic would you use to represent the data?

Lets say you have a Product entity that is made up of three tables (Prices, Text, and Photos) (you could have sets of price for different regions, different text for localization, and different photos). (Sounds like a builder pattern) Would you create a slice of these tables grabbing the right prices, text, and photos in to a single List? Since Lists may be proprietary, would you use a Dictionary object?

I thank you for your answers. I am very interested in the "standard and proper" way to do it rather than 101 possibilities.

Another quick question: is Entity Framework ready for a complicated database yet? There are a lot of constructs that Linq2SQL likes that EF does not. EF seems to require identity fields as primary keys (HAHA), but it seems like every demo does this. I want to use EF, but I constantly fail to make it work, falling back to Linq2SQL.

+3  A: 

If you keep the L2S on the other side of the Repository facade (remember, that's all a Repository is - a facade) then you decouple the rest of your application from L2S. This means that the job of the code behind your repository is to turn the L2S into "domain" objects, custom classes, and then the Repository returns those.

In this sense, the Repository is returning fully formed "Product" objects with all their related Price, Text, and Photo data. This is called an Aggregate Root.

There shouldn't be a problem with Lists, since they are CLR objects.

As far as EF for advanced scenarios, my advice would be not yet, for the reasons you note.

jlembke
Very interesting. I read about half of that blue book so far. Ron Conerys web casts review some of these concepts too.
Dr. Zim
It's powerful stuff and deep water, but the beauty of it is that you can borrow from DDD without going with it 100%, which you may not want to do the first time out. John Saunders' idea is similar - put a barrier between you and the L2S and return another representation of your data.
jlembke
I personally have not run into a scenario that EF could not cover. Just ones that did not work "out of the box" I would say that it is ready for business. Check out IdeaBlade's DevForce EF product if you would like even more functionality.
jwendl
Not denigrating EF. It will be a great tool soon, but it needs one more pass. "Out of the box" solutions are a holy grail for production application. Solutions that we spent 8 weeks on with the Microsoft devs personally involved, and never found an answer for, we were able to rewrite in L2S in just a day. So, advanced scenarios are going to be a little more of a challenge in EF.
jlembke
Scott Guthrie had a nice explanation of the Repository pattern in the MVC book, first chapter. Very useful. MVC is a good tool to focus on the DDD concepts.
Dr. Zim
+2  A: 

The standard mechanism I'd use to represent the data is a Data Transfer Object. I would never return a LINQ to SQL or Entity Framework object across a service boundary, and I would hesitate to return it across a layer boundary of any kind. This is because these objects will serialize implementation-dependant data.

John Saunders
Yes this should be the accepted answer. DTOs are the way to allow abstraction from your ORM strategy and your UI bindings through Repository methods.
jwendl
@jwendl - You don't seem happy with my answer, so I'm curious, as a self-check, how my answer conflicts with yours? Whether you return a "DTO" or a Domain Aggregate through the repository is simply a matter of usage. If all you need is a DTO, then fine, but I'm thinking Domain Driven Design here, which is a perfect fit for MVC.
jlembke