How do I delete a record using Linq to SQL using only the primary key, without having to retrieve the exsting record from the database?
+2
A:
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();
thekaido
2010-03-08 05:18:10
+1 yup basically you need straight SQL for this, Linq-to-SQL doesn't support it natively....
marc_s
2010-03-08 05:53:02