尝试插入时linq to sql错误

时间:2013-11-21 13:38:16

标签: linq-to-sql

我试图做一个简单的插入,但我遇到了错误......

Error   10  The type arguments for method 'System.Data.Linq.Table<RequestSystem.User>.InsertAllOnSubmit<TSubEntity>(System.Collections.Generic.IEnumerable<TSubEntity>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

我的代码是

        `UserModel User = new UserModel();
        User.MudID = a[1];
        User.Name = Session["username"].ToString();
        User.Email = Session["email"].ToString();`


        DataClasses1DataContext dt = new DataClasses1DataContext();

        dt.Users.InsertAllOnSubmit(User);

        dt.SubmitChanges();

1 个答案:

答案 0 :(得分:0)

请改用以下内容:

dt.Users.InsertOnSubmit(User);

这将插入对象的单个实例。使用InsertAllOnSubmit需要一组对象