asp.net mvc - Cannot add rows to a table in LINQ to EntityFramework - AddObject and InsertOnSubmit BOTH missing -


i know it's supposed 1 or other depending on whether using linq sql or linq entities ideas why neither option (addobject or insertonsubmit) available me? using linq entities shouldn't expect see addobject?

update: per request, adding code.

controller:

 using system.data;  using system.data.entity;  using system.linq;   ...unimportant code...   private datamodel db = new datamodel(); // <-- datamodel.edmx   ...unimportant code...      [httppost]     public actionresult processapplication (httppostedfilebase file) {          jobboardusersmodel jm = new jobboardusersmodel();          ...jm properties set...          db.jobboardusers.add(jm) // <- here cannot use addobject or add          client.send(message);          jobdetails.isapplied = true;         return redirecttoaction("index", jobdetails);     } 

model:

public class jobsummarymodel {     public int? id { get; set; }     public string name { get; set; }     public string city { get; set; }     public string postalcode { get; set; }     public string jobdescription { get; set; } } 

addobject() method on objectset<t>, accessible on objectcontext.but if you're using entity framework 4.1 or newer, you're working dbcontext, facade on more complicated objectcontext api.

the equivalent of addobject() on dbset<t> (which you're working in dbcontext) add().

see: add entity using dbcontext

you can access objectcontext if ever need access not available on dbcontext...

var objectcontext = ((iobjectcontextadapter)context).objectcontext; 

as insertonsubmit(), available in linq sql.

--- update ---

jobboardusersmodel jm = new jobboardusersmodel(); 

should be...

jobboarduser jm = new jobboarduser(); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -