是否可以让 LINQ to SQL 使用 PK 删除记录,而无需先加载记录?类似于NHibernate的代理对象功能?
Is it possible to get LINQ to SQL to delete a record using the PK, without loading the record first? Similar to NHibernate's proxy object functionality?
你应该可以这样做:
var person = new Person();
person.ID = someID;
using (var context = new DataContext(connString))
{
context.Persons.Attach(person, false); //attach is as unmodified
context.Persons.DeleteOnSubmit(person); //remove it
context.SubmitChanges(); //submit changes to db
}
这篇关于删除 LINQ to SQL 记录而不先加载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!