开发者

How to insert a new record with LinqToSql?

开发者 https://www.devze.com 2023-03-10 05:19 出处:网络
Googling shows there is to be an \"Add\" method for this, but there seems to 开发者_开发百科be no Add or anything alike in my LinqToSQL table classes. I\'ve tried \"Attach\", but with no effect :-(

Googling shows there is to be an "Add" method for this, but there seems to 开发者_开发百科be no Add or anything alike in my LinqToSQL table classes. I've tried "Attach", but with no effect :-(

I use VS2010, .Net 4 and SQL Server 2008 R2.

My tables have no surrogate ID but a natural composite primary key.


yourDatacontext.yourlinqClass.InsertOnSubmit(new yourlinqClass());

yourDatacontext.SubmitChanges();


It's InsertOnSubmit() for LinqToSQL:

ctx.MyClass.InsertOnSubmit(newinstance);
0

精彩评论

暂无评论...
验证码 换一张
取 消