在将数据插入 oracle 数据库代码时,使用带 entity framework 的 MVC 自动为 id 生成值 0
While inserting data into the oracle database code automatically generate value 0 for id using MVC with entity framework
在将数据插入 Oracle 数据库代码时,使用带有实体 framework.How 的 MVC 自动为 id 生成值 0 来解决此问题。
public ActionResult AddNewNode(AddNode model)
{
try
{
if (ModelState.IsValid)
{
using (Nspira_DBContext entity = new Nspira_DBContext())
{
TBL_ACCESSRIGHTS hierarchyDetail = new TBL_ACCESSRIGHTS()
{
NAME = model.NodeName,
PID = model.ParentName,
};
entity.TBL_ACCESSRIGHTS.Add(hierarchyDetail);
entity.SaveChanges();
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
throw ex;
}
return Json(new { success = false }, JsonRequestBehavior.AllowGet);
}
我的 table 有 ID、NAME 和 PID column.While 在数据库中插入查询意味着它生成序列 number.While 通过代码插入数据意味着它不会创建 sequence.It 获取值作为 0 automatically.How 来解决这个问题。
如何解决this.Please,哪位大侠帮帮我
if (ModelState.IsValid)
{
using (Nspira_DBContext entity = new Nspira_DBContext())
{
int objid = entity.TBL_ACCESSRIGHTS.Max(p => p.ID);
TBL_ACCESSRIGHTS hierarchyDetail = new TBL_ACCESSRIGHTS()
{
ID = objid + 1,
NAME = model.NodeName,
PID = model.ParentName,
};
entity.TBL_ACCESSRIGHTS.Add(hierarchyDetail);
entity.SaveChanges();
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
}
请试试这个
在将数据插入 Oracle 数据库代码时,使用带有实体 framework.How 的 MVC 自动为 id 生成值 0 来解决此问题。
public ActionResult AddNewNode(AddNode model)
{
try
{
if (ModelState.IsValid)
{
using (Nspira_DBContext entity = new Nspira_DBContext())
{
TBL_ACCESSRIGHTS hierarchyDetail = new TBL_ACCESSRIGHTS()
{
NAME = model.NodeName,
PID = model.ParentName,
};
entity.TBL_ACCESSRIGHTS.Add(hierarchyDetail);
entity.SaveChanges();
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
throw ex;
}
return Json(new { success = false }, JsonRequestBehavior.AllowGet);
}
如何解决this.Please,哪位大侠帮帮我
if (ModelState.IsValid)
{
using (Nspira_DBContext entity = new Nspira_DBContext())
{
int objid = entity.TBL_ACCESSRIGHTS.Max(p => p.ID);
TBL_ACCESSRIGHTS hierarchyDetail = new TBL_ACCESSRIGHTS()
{
ID = objid + 1,
NAME = model.NodeName,
PID = model.ParentName,
};
entity.TBL_ACCESSRIGHTS.Add(hierarchyDetail);
entity.SaveChanges();
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
}
请试试这个