Entity Framework and the repository pattern (mvc storefront)

asp.net asp.net-mvc domain-driven-design entity entity-framework

Question

Can anyone give a helping hand? I've been watching the videos for the MVC storefront and have created my own website using these techniques i.e. DDD, Repository pattern but I wish to use Entity Framework.

In the Interfaces it returns IQueryable but with Entity Framework should I return ObjectQuery instead? - I will be using LINQ.

Also in the storedfront example it goes something like this: IQueryable<Category> GetCategories();

Also in the MVC store the Category class was a built entity class (standard class) but with Entity Framework these classes are prebuilt in the object context - are they not?

So I should need to build them?

I am a little confused. If anyone has any helpful example or code it would be really helpful.

As I say, I have watched the videos from The MVC storefront using linq2sql but really would like to use Entity Framework.

Any ideas?

Thanks

Smithy

1
13
10/25/2013 8:18:12 AM

Popular Answer

Let me answer your questions one at a time:

Your repositories should return IQueryable<T>, not ObjectQuery. The reason is that the whole purpose of the repository pattern is to abstract away the specifics of your data store. This allows you to do things like substitute a mock repository when you unit test your controllers. If you make the repository return ObjectQuery, then you are not abstracting away the Entity Framework. Another way of saying this is the users of your repository should not know, as much as possible, that it is the Entity Framework which is doing the O/R mapping.

In order to use the greater than and less than symbols in paragraph text in Stack Overflow, you must escape them as you would in HTML, i.e.:

&lt;

You do not need to do this in a code block; in code blocks, you just type the less than/greater than symbol.

9
4/30/2011 5:09:12 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow