简体   繁体   中英

Linq To SQL : Insert data

I have a database, I create a dbml file and drop the tables it. I can get data like this :

MyDBContext db = new MyDBContext ();

var query =
       (from lg in db.Languages
        select lg).ToList<Languages>();

No problem, I get the data.

I'd like insert, I tried this :

 db.Languages.Add(new Language() { ..... });
 db.SubmitChanges();

The "Add" does not exist in the method list .....

What is the solution ?

Thanks,

PS : it's a project .NET 3.5 with VS2010

Instead of

db.Languages.Add(new Language() { ..... });

I think you want this:

db.Languages.InsertOnSubmit(new Language() { ..... });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM