3

削除ストアド プロシージャを特定の型の削除メソッドにマップできることを理解しています。

ただし、これには、取得したオブジェクトをコンテキストのDeleteObjectメソッドに渡す必要があります。

これでも十分ですが、2000 行を削除したい場合はどうすればよいでしょうか。最初にデータベースから 2000 行を取得してループ呼び出しを行わずに、Linq to Entities でこれを行うことはできますDeleteObjectか?

そのような機能が Linq to Entities に存在せず、これが事実であることがわかっている場合は、そう言ってください。他のオプションを調査します!

直接存在しない場合は、Linq を介して Stored Proc をエンティティにパイプすることで達成できますか?

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 に答える