首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

LINQ增多一条数据,报错,求解决

2012-12-29 
LINQ增加一条数据,报错,求解决Error1The type arguments for method System.Data.Linq.TableDAL.Person

LINQ增加一条数据,报错,求解决
Error1The type arguments for method 'System.Data.Linq.Table<DAL.Person>.InsertAllOnSubmit<TSubEntity>(System.Collections.Generic.IEnumerable<TSubEntity>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

LinqDBDataContext db = new LinqDBDataContext(LinqSystem.constring);
            Model.Person person = new Model.Person();
            person.Id = Id;
            person.Name = name;
            db.Persons.InsertAllOnSubmit(person);
            db.SubmitChanges();

[解决办法]
LinqDBDataContext db = new LinqDBDataContext(LinqSystem.constring);
            db.Persons person = new db.Persons();
            person.Id = Id;
            person.Name = name;
            db.Persons.InsertOnSubmit(person);
            db.SubmitChanges();
[解决办法]
引用:
Error1The type arguments for method 'System.Data.Linq.Table<DAL.Person>.InsertAllOnSubmit<TSubEntity>(System.Collections.Generic.IEnumerable<TSubEntity>)' cannot be inferred from the usage. Try spec……

一条数据:
Persons person=new Persons();
person.Id=Id;
person.Name=name;
db.Persons.InsertOnSubmit(person);
db.SubmitChanges();

多条数据:
List<Persons> persons=new List<Persons>();
persons.Add(……)

db.Persons.InsertAllOnSubmit(persons);
db.SubmitChanges();

热点排行