Entity Framework and the repository pattern (mvc storefront)

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


Can anybody provide a hand here? I've been studying the MVC storefront tutorials, and I used DDD and the Repository design to build my own website. However, I want to utilize Entity Framework.

If I want to use Entity Framework, should I return ObjectQuery rather than IQueryable, as it does in the Interfaces? - I'll be using LINQ.

Additionally, in the storedfront example, something similar happens: GetCategories() in IQueryableCategory>;

The Category class was a built-in entity class in the MVC store as well (a normal class), but with Entity Framework, aren't these classes already generated in the object context?

I guess I should create them then?

I'm a bit perplexed. It would be really useful if somebody could provide some examples or code.

I've used linq2sql to watch the videos from The MVC Storefront, however I'd actually want to utilize Entity Framework.

Any thoughts?



10/25/2013 8:18:12 AM

Popular Answer

Let me respond to each of your inquiries one by one:

Your repositories should return ObjectQuery and IQueryableT>, respectively. The repository pattern's primary goal is to abstract away the characteristics of your data storage, which is why. This enables you to replace a fake repository while unit testing your controllers, for example. You are not hiding the Entity Framework if you have the repository return an ObjectQuery. Another way to put it is that, to the greatest extent feasible, users of your repository shouldn't be aware that the Entity Framework is doing the O/R mapping.

The larger than and less than symbols must be escaped just like in HTML in order to be used in paragraph content on Stack Overflow, i.e.


In code blocks, you merely write the less than/greater than sign; this is not necessary.

4/30/2011 5:09:12 PM

Related Questions


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