crud - Getting metadata error while trying to save values to DB using Entity Framework -


i little new entity framework.

i created sample applicaiton save values db table using entity framework.

i have given below code snippet.

[httppost]         public actionresult employee(employeemodel model)         {             if (modelstate.isvalid)             {                 // insert                 var _insert = new employeemodel                 {                     firstname = model.firstname,                     lastname = model.lastname,                     initial = model.initial,                     dob = model.dob,                     doj = model.doj,                     role = model.role,                     city = model.city,                     state = model.state,                     country = model.country                 };                 db.employee_master.addobject(_insert);                 db.savechanges();                 return view();             } 

i getting below compilation error in "db.employee_master.addobject(_insert);" line.

"the best overloaded method match 'system.data.objects.objectset.addobject(financialmanagementsystem.models.employee_master)' has invalid arguments s:\sourcecode\financialmanagementsystem\financialmanagementsystem\controllers\employeecontroller.cs"

what doing wrong?

use add instead addobject. employeemodel model transfer data between view , controller. table want insert into? take example, have table employee.

public dbset<blog> employees { get; set; }   db.employees.add(new employee {firstname = model.firstname,....}); 

but if still want use addobject:

db.employee_master.addobject(new employee {...}); //employee name of class represent employee_master, maybe employee_master of problem. 

here different between add , addobject: http://blog.cincura.net/232485-someentityset-addobject-vs-addtosomeentityset-methods/


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -