tjapple tjapple - 3 months ago 43
C# Question

Entity Framework equivalent of InsertonSubmit

I know there is a question with basically the same header but is different in my case. I moved from Linq-to-SQL to Entity Framework (which I am a little new to) and I have a method where I use

InsertOnSubmit
, and so I found out it is in Linq-to-SQL and not in Entity Framework, any ideas?

Linq-to-SQL:

dc.tblTruckDetails.InsertOnSubmit(tblInsert);
dc.SubmitChanges();

Answer

You don't need to call InsertOnSubmit in Entity Framework.

You can simply create a new object of what you want to add in database and then call SaveChanges method.

Entities entities = new Entities();

Employee emp = new Employee();
emp.Name = "Mairaj";

entities.Employees.Add(emp);
entities.SaveChanges();
Comments