案例代码如下:

Model1Container ef = new Model1Container();
//查询
var liuyan = ef.LiuYan.Where(m => m.BH == "1").FirstOrDefault();

//查询后更新
liuyan.QQ = "1183816006";
ef.SaveChanges();

//插入
var liy = new LiuYan();
ef.LiuYan.Add(liy);
ef.SaveChanges();

//无查询直接附加全字段更新
ef.LiuYan.Attach(liy);
ef.SaveChanges();

//按需更新指定字段
var liuyanupdate= ef.Entry<LiuYan>(liy);
liuyanupdate.State = EntityState.Unchanged;
liuyanupdate.Property("Bh").IsModified = true;
liuyanupdate.Property("qq").IsModified = true;
ef.SaveChanges();

 

//无查询直接删除数据
liuyanupdate.State = EntityState.Deleted;
ef.SaveChanges();

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-10-05
  • 2021-10-25
  • 2022-02-27
猜你喜欢
  • 2021-10-12
  • 2022-03-05
  • 2021-09-24
  • 2021-06-22
  • 2021-12-17
  • 2022-01-10
  • 2022-12-23
相关资源
相似解决方案