3

我知道我可以将删除存储过程映射到特定类型的删除方法。

但是,这需要将检索到的对象传递给我的上下文DeleteObject方法。

这已经够糟糕了,但是如果我想删除 2000 行呢?我可以使用 Linq to Entities 执行此操作,而无需先从数据库中检索这 2000 行并通过循环调用DeleteObject吗?

如果Linq to Entities 中不存在此类功能,并且您知道是这种情况,那么请直接说出来,我会调查其他选项!

如果它不直接存在,我可以通过 Linq 将存储过程管道传输到实体来实现吗?

4

1 回答 1

3

是的,你可以这样做。从这个提示

// Create an entity to represent the Entity you wish to delete
// Notice you don't need to know all the properties, in this
// case just the ID will do.
Category stub = new Category { ID = 4 };
// Now attach the category stub object to the "Categories" set.
// This puts the Entity into the context in the unchanged state,
// This is same state it would have had if you made the query
ctx.AttachTo("Categories", stub);
// Do the delete the category
ctx.DeleteObject(stub);
// Apply the delete to the database
ctx.SaveChanges();

有关详细信息和并发症,请参阅完整提示

于 2009-10-21T15:37:10.963 回答