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

你离开我真会死。 提交于 2019-12-13 03:42:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!