コード例 #1
0
        public int Update <TEntity>(TEntity entity) where TEntity : class
        {
            dbcontext.Set <TEntity>().Attach(entity);
            PropertyInfo[] props = entity.GetType().GetProperties();
            foreach (PropertyInfo prop in props)
            {
                if (prop.GetValue(entity, null) != null && ExcludeType.IsExclude(prop))
                {
                    if (prop.GetValue(entity, null).ToString() == "&nbsp;")
                    {
                        dbcontext.Entry(entity).Property(prop.Name).CurrentValue = null;
                    }

                    dbcontext.Entry(entity).Property(prop.Name).IsModified = true;
                }
            }
            return(dbTransaction == null?this.Commit() : 0);
        }
コード例 #2
0
ファイル: RepositoryBase.T.cs プロジェクト: panda-lqc/Blog
 public int Update(TEntity entity)
 {
     dbcontext.Set <TEntity>().Attach(entity);
     PropertyInfo[] props = entity.GetType().GetProperties();
     foreach (PropertyInfo prop in props)
     {
         if (ExcludeType.IsExclude(prop))
         {
             if (prop.GetValue(entity, null) != null)
             {
                 if (prop.GetValue(entity, null).ToString() == "&nbsp;")
                 {
                     dbcontext.Entry(entity).Property(prop.Name).CurrentValue = null;
                 }
                 dbcontext.Entry(entity).Property(prop.Name).IsModified = true;
             }
             else
             {
                 dbcontext.Entry(entity).Property(prop.Name).IsModified = true;
             }
         }
     }
     return(dbcontext.SaveChanges());
 }