sql:'MYDataContext'不包含'InsertOnSubmit'的定义 [英] ling to sql: 'MYDataContext' does not contain a definition for 'InsertOnSubmit'

查看:117
本文介绍了sql:'MYDataContext'不包含'InsertOnSubmit'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向表中添加一行:

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();
    }

但我收到此错误:

'MYDataContext'不包含'InsertOnSubmit'的定义,并且找不到扩展方法'InsertOnSubmit'接受类型为'MYDataContext'的第一个参数(您是否缺少using指令或程序集引用?)

'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?)

我该如何解决?

推荐答案

datacontext本身没有InsertOnSubmit. 您需要添加实体.像这样:

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

db.NotificationLog s .InsertOnsubmit(n)

db.NotificationLogs.InsertOnsubmit(n)

这篇关于sql:'MYDataContext'不包含'InsertOnSubmit'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆