I am writing a generic repository for entity framework and am confused as to what the difference between these calls are:
ObjectContext.CreateObjectSet<T>
ObjectContext.CreateQuery<T>
DbContext.Set<T>
I want a generic repository that both supports context generated from .edmx files as well as code first DbContext, so I've got this:
public abstract class EntityRepository<TClass>
where TClass : class, new()
{
//private readonly TContext _context;
private readonly ObjectSet<TClass> _objectSet;
protected EntityRepository(IObjectContextAdapter context)
{
_objectSet = context.ObjectContext.CreateObjectSet<TClass>();
}
protected EntityRepository(ObjectContext context)
{
_objectSet = context.CreateObjectSet<TClass>();
}
public ObjectSet<TClass> Query()
{
return _objectSet;
}
}
In the examples I have seen online I've seen all 3 used, what is the actual differences between them? Is one better performance wise? I know you can write LINQ queries against the contexts using all 3 methods.