/// <summary>
        ///  删除指定编号的记录
        /// </summary>
        /// <param name="id"> 实体记录编号 </param>
        /// <param name="isSave"> 是否执行保存 </param>
        /// <returns> 操作影响的行数 </returns>
        public virtual async Task <int> DeleteAsync(object id, bool isSave = true)
        {
            PublicHelper.CheckArgument(id, "id");
            TEntity entity = UnitOfWorkContext.Set <TEntity>().Find(id);

            return(entity != null ? await SaveAsync() : 0);
        }
        /// <summary>
        ///  删除指定编号的记录
        /// </summary>
        /// <param name="id"> 实体记录编号 </param>
        /// <param name="isSave"> 是否执行保存 </param>
        /// <returns> 操作影响的行数 </returns>
        public virtual int Delete(object id, bool isSave = true)
        {
            PublicHelper.CheckArgument(id, "id");
            TEntity entity = UnitOfWorkContext.Set <TEntity>().Find(id);

            return(entity != null?Delete(entity, isSave) : 0);
        }
예제 #3
0
        public virtual int Update(Expression <Func <TEntity, object> > propertyExpression, bool isSave = true, params TEntity[] entities)
        {
            UnitOfWorkContext.RegisterModified(propertyExpression, entities);
            if (!isSave)
            {
                return(0);
            }
            var dbSet = UnitOfWorkContext.Set <TEntity>();

            dbSet.Local.Clear();
            foreach (var entity in entities)
            {
                UnitOfWorkContext.Entry(entity).State = EntityState.Modified;
            }
            return(UnitOfWorkContext.Commit());
        }
 /// <summary>
 /// 查找指定主键的实体记录
 /// </summary>
 /// <param name="key"> 指定主键 </param>
 /// <returns> 符合编号的记录,不存在返回null </returns>
 public virtual TEntity Query(object key)
 {
     PublicHelper.CheckArgument(key, "key");
     return(UnitOfWorkContext.Set <TEntity>().Find(key));
 }
 /// <summary>
 /// 查找指定主键的实体记录
 /// </summary>
 /// <param name="key"> 指定主键 </param>
 /// <returns> 符合编号的记录,不存在返回null </returns>
 public virtual async Task <TEntity> QueryAsync(object key)
 {
     PublicHelper.CheckArgument(key, "key");
     return(await UnitOfWorkContext.Set <TEntity>().FindAsync(key));
 }
 public GenericRepository(UnitOfWorkContext _context)
 {
     context = _context;
     dbSet   = context.Set <T>();
 }
예제 #7
0
 public virtual TEntity GetById(object id, bool getDeleted = false)
 {
     return(UnitOfWorkContext.Set <TEntity>().FirstOrDefault(AppendSofeDeletedExpr(x => x.Id == id, getDeleted)));
 }
예제 #8
0
        public virtual int Delete(Expression <Func <TEntity, bool> > predicate, bool isSave = true)
        {
            var entities = UnitOfWorkContext.Set <TEntity>().Where(predicate).ToList();

            return(entities.Count > 0 ? Delete(entities, isSave) : 0);
        }
예제 #9
0
        public virtual int Delete(object id, bool isSave = true)
        {
            var entity = UnitOfWorkContext.Set <TEntity>().Find(id);

            return(entity != null?Delete(entity, isSave) : 0);
        }