问题
I am trying to add a row to a table:
MYDataContext dc = new MYDataContext("MYConnectionString");
using (MYDataContext db = new MYDataContext("MYConnectionString"))
{
NotificationLog n = new NotificationLog();
n.result = result;
n.context = message;
n.tomobiles = phoneprefix + phone;
n.datesent = DateTime.Now;
n.SMSprovider = provider;
db.InsertOnSubmit(n);
db.SubmitChanges();
}
But I get this error:
'MYDataContext' does not contain a definition for 'InsertOnSubmit' and no extension method 'InsertOnSubmit' accepting a first argument of type 'MYDataContext' could be found (are you missing a using directive or an assembly reference?)
How I can fix that?
回答1:
There is no InsertOnSubmit on the datacontext itsself. You need to add the entity. Something like:
db.NotificationLogs.InsertOnsubmit(n)
来源:https://stackoverflow.com/questions/49979398/ling-to-sql-mydatacontext-does-not-contain-a-definition-for-insertonsubmit