public IQueryable <T> Query <T>(Expression <Func <T, bool> > filter = null) where T : class { IQueryable <T> query = dataContext.Set <T>(); if (filter != null) { query = query.Where(filter); } return(query); }
public int Update(TEntity entity) { dbcontext.Set <TEntity>().Attach(entity); PropertyInfo[] props = entity.GetType().GetProperties(); foreach (PropertyInfo prop in props) { if (prop.GetValue(entity, null) != null) { if (prop.GetValue(entity, null).ToString() == " ") { dbcontext.Entry(entity).Property(prop.Name).CurrentValue = null; } dbcontext.Entry(entity).Property(prop.Name).IsModified = true; } } return(dbcontext.SaveChanges()); }
/// <summary> /// 獲取實體集合 /// </summary> /// <returns></returns> public IQueryable <TEntity> GetAll() { return(_dbContext.Set <TEntity>().Where(CreateBaseFilter())); }