public void Delete(Product product)
 {
     if (Context.Entry(product).State == EntityState.Detached)
     {
         Dbset.Attach(product);
     }
     Dbset.Remove(product);
 }
 public void Update(Product product)
 {
     //var x = Context.Entry(product).State;
     Dbset.Attach(product);
     //var y = Context.Entry(product).State;
     Context.Entry(product).State = EntityState.Modified;
     //var z = Context.Entry(product).State;
 }
示例#3
0
 /// <summary>
 /// 修改单条数据
 /// </summary>
 /// <param name="entity">TEntity实体</param>
 /// <exception cref="System.ArgumentNullException">entity</exception>
 public virtual void Update(TEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     Dbset.Attach(entity);
     _dataContext.Entry(entity).State = EntityState.Modified;
 }
示例#4
0
        /// <summary>
        /// Updates the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <param name="action">The action.</param>
        public virtual void Update(Expression <Func <TEntity, bool> > @where, Action <TEntity> action)
        {
            var objects = Dbset.Where(where);

            //objects.ForEach(entity =>
            //{
            //    Dbset.Attach(entity);
            //    var entityEntry = _dataContext.Entry(entity);
            //    action(entity);
            //    entityEntry.State = EntityState.Modified;
            //});
            foreach (TEntity entity in objects)
            {
                Dbset.Attach(entity);
                var entityEntry = _dataContext.Entry(entity);
                action(entity);
                entityEntry.State = EntityState.Modified;
            }
        }