views:

51

answers:

3

My controller's call to repository insert method all the values are passed but it doesn't get inserted in my table..

My controller method,

[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();
            }
        }

and my repository,

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;
}

What am i missing here any suggestion....

+2  A: 

As far as I can see, you're missing a db.SubmitChanges(); to save to the database.

Chris
@Chris oh god how did i miss that!
Pandiya Chendur
it's easy done - I had the same issue this morning! :-)
Chris
@Chris Linq-to-sql first time for me... Never do this mistake again...
Pandiya Chendur
+1  A: 
db.Materials.InsertOnSubmit(mat);
db.SubmitChanges(); // <---------------
return materialsObj;
Fabian
+1  A: 

Aren't you missing a call to SubmitChanges?

db.Materials.InsertOnSubmit(mat);
db.SubmitChanges();
bruno conde