ling to sql: 'MYDataContext' does not contain a definition for 'InsertOnSubmit'

565 Views Asked by At

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 are 1 best solutions below

0
On

There is no InsertOnSubmit on the datacontext itsself. You need to add the entity. Something like:

db.NotificationLogs.InsertOnsubmit(n)