Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取错误';表<;愿望清单>';不包含对';添加';没有扩展方法';添加';与edmx linq一起使用mvc#?_C#_Linq_Asp.net Mvc 4_Linq To Sql - Fatal编程技术网

获取错误';表<;愿望清单>';不包含对';添加';没有扩展方法';添加';与edmx linq一起使用mvc#?

获取错误';表<;愿望清单>';不包含对';添加';没有扩展方法';添加';与edmx linq一起使用mvc#?,c#,linq,asp.net-mvc-4,linq-to-sql,C#,Linq,Asp.net Mvc 4,Linq To Sql,我将使用MVC为“将产品添加到愿望列表”表创建一个模块。为此,我使用了实体框架。我已经在model文件夹中装入了dbml类。我打算将产品添加到愿望列表中,我遇到如下错误: “表”不包含“添加”的定义,也不包含 扩展方法“Add”接受类型为的第一个argumnets 无法找到“table”。(是否缺少using指令 还是部件参考?“ 我不知道为什么会在这里产生这个错误,以及我的代码中缺少什么。任何朋友,请让我知道。下面我列出了我的代码 这是我在to表定义中的dbml类: [global::Syst

我将使用MVC为“将产品添加到愿望列表”表创建一个模块。为此,我使用了实体框架。我已经在model文件夹中装入了dbml类。我打算将产品添加到愿望列表中,我遇到如下错误:

表”不包含“添加”的定义,也不包含 扩展方法“Add”接受类型为的第一个argumnets 无法找到“table”。(是否缺少using指令 还是部件参考?

我不知道为什么会在这里产生这个错误,以及我的代码中缺少什么。任何朋友,请让我知道。下面我列出了我的代码

这是我在to表定义中的dbml类:

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.WishList")]
public partial class WishList : INotifyPropertyChanging, INotifyPropertyChanged
{

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

    private int _Id;

    private string _Laminate_Sheet_Smo;

    private System.Nullable<int> _CustmorId;

    public List<WishList> list { get; set; }

    #region Extensibility Method Definitions
    partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdChanging(int value);
partial void OnIdChanged();
partial void OnLaminate_Sheet_SmoChanging(string value);
partial void OnLaminate_Sheet_SmoChanged();
partial void OnCustmorIdChanging(System.Nullable<int> value);
partial void OnCustmorIdChanged();
#endregion

    public WishList()
    {
        OnCreated();
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
    public int Id
    {
        get
        {
            return this._Id;
        }
        set
        {
            if ((this._Id != value))
            {
                this.OnIdChanging(value);
                this.SendPropertyChanging();
                this._Id = value;
                this.SendPropertyChanged("Id");
                this.OnIdChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Laminate_Sheet_Smo", DbType="NVarChar(50)")]
    public string Laminate_Sheet_Smo
    {
        get
        {
            return this._Laminate_Sheet_Smo;
        }
        set
        {
            if ((this._Laminate_Sheet_Smo != value))
            {
                this.OnLaminate_Sheet_SmoChanging(value);
                this.SendPropertyChanging();
                this._Laminate_Sheet_Smo = value;
                this.SendPropertyChanged("Laminate_Sheet_Smo");
                this.OnLaminate_Sheet_SmoChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CustmorId", DbType="Int")]
    public System.Nullable<int> CustmorId
    {
        get
        {
            return this._CustmorId;
        }
        set
        {
            if ((this._CustmorId != value))
            {
                this.OnCustmorIdChanging(value);
                this.SendPropertyChanging();
                this._CustmorId = value;
                this.SendPropertyChanged("CustmorId");
                this.OnCustmorIdChanged();
            }
        }
    }

    public event PropertyChangingEventHandler PropertyChanging;

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void SendPropertyChanging()
    {
        if ((this.PropertyChanging != null))
        {
            this.PropertyChanging(this, emptyChangingEventArgs);
        }
    }

    protected virtual void SendPropertyChanged(String propertyName)
    {
        if ((this.PropertyChanged != null))
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
这是我的控制器代码:

    DataClasses1DataContext db = new DataClasses1DataContext();
if (!string.IsNullOrEmpty(CookieHelper.GetCookieValue(CookieKeys.WishLaminateId)))
            {

                string pids = CookieHelper.GetCookieValue(CookieKeys.WishLaminateId);
                var v = pids.Split(',');
                var length = v.Length;

                for (int i = 0; i < length; i++)
                {
                    WishList addtbl = new WishList();
                    addtbl.Laminate_Sheet_Smo = v[i];
                    addtbl.CustmorId = Convert.ToInt32(CookieHelper.GetCookieValue(CookieKeys.CustId));
                    db.WishLists.Add() // here  i am getting error 
                    int UserId = Convert.ToInt32(CookieHelper.GetCookieValue(CookieKeys.CustId));
                    var h = db.WishLists.Where(x => x.CustmorId == UserId).Count();
                    CookieHelper.SetCookie(CookieKeys.CountOfCart, h.ToString());
                }
            }
DataClasses1DataContext db=newdataclasses1datacontext();
如果(!string.IsNullOrEmpty(CookieHelper.GetCookieValue(CookieKeys.WishLaminateId)))
{
字符串pids=CookieHelper.GetCookieValue(CookieKeys.WishLaminateId);
var v=pids.Split(',');
变量长度=v.长度;
for(int i=0;ix.CustmorId==UserId.Count();
SetCookie(CookieKeys.CountOfCart,h.ToString());
}
}
这是我的代码,请任何人帮助我如何修复这个错误

试试这个:

WishList addtbl = new WishList();
addtbl.Laminate_Sheet_Smo = v[i];
addtbl.CustmorId = Convert.ToInt32(CookieHelper.GetCookieValue(CookieKeys.CustId));
db.WishLists.Add(addtbl); //Add the object into the DBSet
db.SaveChanges(); //Save changes to database.

@David Browne您知道如何修复此错误吗?我认为应该是
db.WishLists.Add(addtbl)
而不是
db.WishLists.Add()
WishList addtbl = new WishList();
addtbl.Laminate_Sheet_Smo = v[i];
addtbl.CustmorId = Convert.ToInt32(CookieHelper.GetCookieValue(CookieKeys.CustId));
db.WishLists.Add(addtbl); //Add the object into the DBSet
db.SaveChanges(); //Save changes to database.