ASP.NET MVC 3 & Unity.MVC3(3)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:50 点击:次
public DbContextRepository(DbContext context)
{
_objectSet = context.Set<T>();
_context = context;
}
public IQueryable<T> AsQueryable()
{
return _objectSet;
}
public IEnumerable<T> GetAll()
{
return _objectSet.ToList();
}
public IEnumerable<T> Find(Expression<Func<T, bool>> where)
{
return _objectSet.Where(where);
}
public T Single(Expression<Func<T, bool>> where)
{
return _objectSet.Single(where);
}
public T First(Expression<Func<T, bool>> where)
{
return _objectSet.First(where);
}
public void Delete(T entity)
{
if (_context.Entry(entity).State == System.Data.EntityState.Detached)
_objectSet.Attach(entity);
_objectSet.Remove(entity);
}
public void Add(T entity)
{
_objectSet.Add(entity);
}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>