我的控制器调用存储库插入方法所有值都被传递但是它没有插入到我的表中..
我的控制器方法,
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude = "Id")]FormCollection collection)
{
try
{
MaterialsObj materialsObj = new MaterialsObj();
materialsObj.Mat_Name = collection["Mat_Name"];
materialsObj.Mes_Id = Convert.ToInt64(collection["MeasurementType"]);
materialsObj.Mes_Name = collection["Mat_Type"];
materialsObj.CreatedDate = System.DateTime.Now;
materialsObj.CreatedBy = Convert.ToInt64(1);
materialsObj.IsDeleted = Convert.ToInt64(1);
consRepository.createMaterials(materialsObj);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
和我的存储库,
public MaterialsObj createMaterials(MaterialsObj materialsObj)
{
Material mat = new Material();
mat.Mat_Name = materialsObj.Mat_Name;
mat.Mat_Type = materialsObj.Mes_Name;
mat.MeasurementTypeId = materialsObj.Mes_Id;
mat.Created_Date = materialsObj.CreatedDate;
mat.Created_By = materialsObj.CreatedBy;
mat.Is_Deleted = materialsObj.IsDeleted;
db.Materials.InsertOnSubmit(mat);
return materialsObj;
}
我在这里错过了什么建议......
答案 0 :(得分:2)
据我所知,你错过了一个db.SubmitChanges();
来保存到数据库。
答案 1 :(得分:1)
db.Materials.InsertOnSubmit(mat);
db.SubmitChanges(); // <---------------
return materialsObj;
答案 2 :(得分:1)
您是否错过了对SubmitChanges
的电话?
db.Materials.InsertOnSubmit(mat);
db.SubmitChanges();