Looks like a Repository Pattern to me, or at least a variation. Why don't you post your whole implementation so we can have a better look. I do it like this...
public class Repository : IRepository
{
ObjectContext _context;
public Repository(ObjectContext context) {
_context = context;
}
public void CommitChanges() {
\_context.SaveChanges();
}
string GetSetName<T>() {
var entitySetProperty =
\_context.GetType().GetProperties()
.Single(p => p.PropertyType.IsGenericType && typeof(IQueryable<>)
.MakeGenericType(typeof(T)).IsAssignableFrom(p.PropertyType));
return entitySetProperty.Name;
}
public void Delete<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T: class, new() {
var query = All<T>().Where(expression);
foreach (var item in query) {
Delete(item);
}
}
public void Delete<T>(T item) where T: class, new() {
\_context.DeleteObject(item);
}
public void DeleteAll<T>() where T: class, new() {
var query = All<T>();
foreach (var item in query) {
Delete(item);
}
}
public void Dispose() {
\_context.Dispose();
}
public T Single<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T: class, new() {
return All<T>().FirstOrDefault(expression);
}
public T Single<T>(Expression<Func<T, bool>> expression, Expression<Func<T, object>> include) where T : class, new()
{
return All<T>(include).FirstOrDefault(expression);
}
public T Single<T>(Expression<Func<T, bool>> expression, params Expression<Func<T, object>>\[\] include) where T : class, new()
{
return All<T>(include).FirstOrDefault(expression);
}
public IQueryable<T> All<T>() where T: class, new() {
return \_context.CreateQuery<T>(GetSetName<T>()).AsQueryable();
}
public IQueryable<T> All<T>(Expression<Func<T, object>> include) where T : class, new()
{
return \_context.CreateQuery<T>(GetSetName<T>()).Include<T>(include).AsQueryable();
}
public IQueryable<T> All<T>(params Expression<Func<T, object>>\[\] include) wher