开发者

How to delete using only the primary key?

How do I delete a record using Linq to SQL using only the primary key, without开发者_高级运维 having to retrieve the existing record from the database?


You should be able to create an instance of the object with the appropriate FK and then Attach() it to the context, Delete() it and then SubmitChanges() which will perform a delete without performing a sql select.

var foo1 = new Foo {Id = 1};
db.Foos.Attach(foo1);
db.Foos.Remove(foo1);
db.SubmitChanges();


Linq to SQL: Delete an entity using Primary Key only - Omar AL ...

http://msmvps.com/blogs/omar/archive/2008/10/30/linq-to-sql-delete-an-entity-using-primary-key-only.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜