public void Change <TEntity>(TEntity entity, DbSet <TEntity> entities = null)
            where TEntity : class, new()
        {
            CheckNullEntity(entity);

            entities = entities ?? GetDbSet <TEntity>();

            if (PageHelper.IsAdd <TEntity, int>(entity))
            {
                entities.Add(entity);
            }
            else
            {
                Attach(entities, entity, EntityState.Modified);
            }
        }
コード例 #2
0
        public async Task <bool> SaveAsync <TEntity>(TEntity entity, DbSet <TEntity> entities = null)
            where TEntity : class, new()
        {
            CheckNullEntity(entity);

            entities = entities ?? GetDbSet <TEntity>();

            if (PageHelper.IsAdd <TEntity, int>(entity))
            {
                entities.Add(entity);
            }
            else
            {
                Attach(entities, entity, EntityState.Modified);
            }
            return(await SaveChangesAsync());
        }