I am trying (and failing) to understand the purpose of the Generic Repository Pattern in the specific instance where it is wrapped around Entity Framework or EF Core.
what is the benefit of writing this:
public void Update(T obj)
{
DbContext.Set<T>().Attach(obj);
DbContext.Entry(obj).State = EntityState.Modified;
DbContext.SaveChanges();
}
When you get the same and more by simply writing it as
public void Update(Movie obj)
{
DbContext.Set<Movie>().Attach(obj);
DbContext.Entry(obj).State = EntityState.Modified;
DbContext.SaveChanges();
}
or
public void Update(Movie obj)
{
var movie = DbContext.Movies.FirsOrDefault(x => x.MovieId == obj.MovieId);
DbContext.Entry(movie).CurrentValues.SetValues(obj);
DbContext.SaveChanges();
}
I guess my real question is why do we wrap a generic repo around what is basically already a generic repository (with more features and optimisations)?
Update
can perform 3 deletions and 5 insertsion along with 15 updates on unrelated objects too.