实体框架在C#中按ID更新记录 [英] entity framework update record by id in c#
本文介绍了实体框架在C#中按ID更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新使用的实体框架
如何将其转换为实体框架c#
query = update cachieroperation set last_used = getdate()+'0:8:0'其中id = 14
How can I convert this to entity framework c#
query = "update cachieroperation set last_used = getdate()+'0:8:0' where id = 14"
推荐答案
应该是这样(我不知道您的类叫什么):
Should be something like(I don't know what your classes are called):
using(var context = new SomeEntities())
{
CarrierOperation carrierOperation = context.CarrierOperations.SingleOrDefault(co=> co.id == 14);
if(carrierOperation != null)
{
carrierOperation.last_used = DateTime.Now.AddMinutes(8);
context.SaveChanges();
}
}
这篇关于实体框架在C#中按ID更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文