Reputation
1,379
Top tag
Next privilege 2,000 Rep.
Edit questions and answers
Badges
2 4 7
Impact
~77k people reached

  • 0 posts edited
  • 0 helpful flags
  • 5 votes cast
Jul
13
awarded  Great Answer
Jul
13
comment Why shouldn't I use the repository pattern with Entity Framework?
Not really, because I'm also employing interfaces, so I can have a method like GetPublished<TEntity>() where TEntity : IPublishable. Sometimes I do tack on more specific methods via a partial class, though.
Jul
13
comment Why shouldn't I use the repository pattern with Entity Framework?
I usually have just one service per database or access method. I use generic methods to query multiple entity types from the same set of methods. I use Ninject to inject my context into my service and then my service into my controllers so everything is neat and tidy.
Jul
7
comment Why shouldn't I use the repository pattern with Entity Framework?
You of course have to change the service. But, what I'm talking about is having stuff like service.GetPublishedBlogPosts() in your controller actions. Then, if you want to switch to something like Web Api, you just have to alter that method, not every single call to it throughout your application. It's even easier if you use interfaces and dependency injection, as then you can just drop in a brand new service implementation and you're off to the races. You can't do this using repositories, since they don't return fully-baked data.
Apr
8
awarded  Populist
Jan
30
answered Leaving intentional bugs in code for testers to find
Jan
5
awarded  Commentator
Jan
5
comment Why shouldn't I use the repository pattern with Entity Framework?
@user2864740: First, notice the prefacing term "low-level". "The purpose of the repository pattern is to abstract away the low-level database querying logic." Second, EF syntax is object-querying logic. It may hit a database behind the scenes, but the same logic applies no matter what the data source is.
Oct
29
comment Why shouldn't I use the repository pattern with Entity Framework?
It's simply not worth the effort when you can get all the abstraction goodness with a much simpler and looser pattern such as services.
Oct
29
comment Why shouldn't I use the repository pattern with Entity Framework?
At the risk of sounding egotistical: they're wrong. Now, as far as the official tutorials go, Microsoft has backed off using repositories from what I've seen since EF6. Regarding the book, i can't speak to why the author chose to use repositories. What i can speak to, as someone in the trenches building large scale applications, is that using the repository pattern with Entity Framework is a maintenance nightmare. Once you move into anything more complex than a handful of repositories, you end up spending exhorbitant amounts of time managing your repositories/unit of work.
Sep
19
awarded  Yearling
Jun
23
awarded  Good Answer
Mar
27
comment Why shouldn't I use the repository pattern with Entity Framework?
@TheZenker, you may not have been exactly following the repository pattern. The strictest difference is the return value. Repositories return queryables, whereas services should return enumerables. Even that's not really that black and white, as there's some overlap there. It's more in how you use it. A repository should just return the set of all objects, which you then further query into, while the service should return the final dataset, and should not support further querying.
Mar
6
comment Why shouldn't I use the repository pattern with Entity Framework?
EF's testability has improved greatly in version 6. You may now fully mock DbContext. Regardless, you could always mock DbSet, and that's the meat of Entity Framework, anyways. DbContext is little more than a class to house your DbSet properties (repositories) in one location (unit of work), especially in a unit testing context, where all the database initialization and connection stuff is not wanted or needed anyways.
Mar
6
comment Why shouldn't I use the repository pattern with Entity Framework?
You can mock DbContext in EF6+ (see: msdn.microsoft.com/en-us/data/dn314429.aspx). Even in lesser versions, you can use a fake DbContext-like class with mocked DbSets, since DbSet implements an iterface, IDbSet.
Mar
5
awarded  Nice Answer
Feb
5
answered ASP.NET MVC SoC when dealing with back end objects (design decision)
Jan
16
awarded  Necromancer
Dec
23
awarded  Yearling
Dec
3
answered Why shouldn't I use the repository pattern with Entity Framework?