请教entity framework中数据更新的问题
1个回答
展开全部
db.Devies 是个DBSet 啊, 应该是
db.Entry(d).State = EntityState.Modified;
db.SaveChanges();
代码:如下
var viewModel = new netsecreContext();
viewModel.Devies=db.Devies;
foreach (Devie d in viewModel.Devies)
{
SimpleSnmp snmp = new SimpleSnmp(d.MsgHostname, d.device_comm);
Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1,
new string[] { ".1.3.6.1.2.1.1.1.0" });
foreach (KeyValuePair<Oid, AsnType> kvp in result)
{
d.device_ios = kvp.Value.ToString();
}
if (ModelState.IsValid)
{
db.Entry(db.Devies).State = EntityState.Modified;
db.SaveChanges();
}
}
return RedirectToAction("Index");
转载,仅供参考。
db.Entry(d).State = EntityState.Modified;
db.SaveChanges();
代码:如下
var viewModel = new netsecreContext();
viewModel.Devies=db.Devies;
foreach (Devie d in viewModel.Devies)
{
SimpleSnmp snmp = new SimpleSnmp(d.MsgHostname, d.device_comm);
Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1,
new string[] { ".1.3.6.1.2.1.1.1.0" });
foreach (KeyValuePair<Oid, AsnType> kvp in result)
{
d.device_ios = kvp.Value.ToString();
}
if (ModelState.IsValid)
{
db.Entry(db.Devies).State = EntityState.Modified;
db.SaveChanges();
}
}
return RedirectToAction("Index");
转载,仅供参考。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询