1 EF更新指定字段.或个更新整个实体
 2 
 3 
 4 
 5 更新整个实体:
 6  public bool Update(Company compay)
 7         {          
 8             if (compay != null)
 9             {
10                 dbContext.Entry<Company>(compay).State = EntityState.Modified;               
11             }
12             return this.SaveChanges() > 0 ? true : false;
13         }
14 
15 
16 更新指定字段:
17 
18  public bool Update( Entity.SoldTo soldModel, List<string[]> list)
19         {        
20                 //更新
21                 DbEntityEntry<Entity.SoldTo> uSoldModel = dbContext.Entry<Entity.SoldTo>(soldModel);
22                 uSoldModel.State = System.Data.EntityState.Unchanged;
23 
24                 foreach (string Field in list[0])
25                 {
26                     uSoldModel.Property(Field).IsModified = true;
27                 }
28             }
29   return this.SaveChanges() > 0 ? true : false;
30 }

 

相关文章:

  • 2022-12-23
  • 2019-01-27
  • 2021-12-22
  • 2022-12-23
  • 2022-03-03
  • 2021-06-25
  • 2021-07-24
  • 2022-03-08
猜你喜欢
  • 2019-09-24
  • 2021-08-30
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案