LLBLGen 级联删除?
有没有什么简单的方法可以在 LLBLGen 中实现“级联删除”?我正在寻找的示例:
您已经有了这些表:
Customer:
-Id
Order:
-Id
-CustomerId
OrderDetail:
-Id
-OrderId
现在,我想删除特定的客户以及依赖于它的所有内容(其所有订单及其所有订单的订单详细信息)。由于如果我在删除以其 Id 作为外键的订单之前删除客户,数据库将会出现异常,因此我几乎需要:
- 获取客户
- 获取客户的订单
- 获取每个订单的 OrderDetails
- 删除每个 OrderDetail
- 删除每个订单
- 删除每个客户
现在,这似乎是一个非常常见的任务 - 我认为某处有某种删除(实体实体ToDelete,bool isRecursive)函数。无论如何,有什么简单的方法可以做到这一点吗?
Is there any easy way to do what seems best described as a "Cascading Delete" in LLBLGen? An example of what I'm looking for:
You've got these tables:
Customer:
-Id
Order:
-Id
-CustomerId
OrderDetail:
-Id
-OrderId
Now, I want to delete a specific Customer and all the things that depend on it (all its orders, and all its orders' orderdetails). Since the database is going to throw a fit if I delete a Customer before deleting the Orders that have its Id as a foreign key, I need to pretty much:
- Get the customer
- Get the customer's Orders
- Get each Orders' OrderDetails
- Delete each OrderDetail
- Delete each Order
- Delete each customer
Now, this seems like a pretty common task- I'd think there's be some sort of Delete(Entity entityToDelete, bool isRecursive) function somewhere. Anyway, is there any easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,LLBLGen Pro 不支持级联删除。我们没有内置它,原因如下:
- 并不总是可以进行级联删除(想象一个菱形模型,其中有两条或多条路径从 a 到 b。这也是为什么 sqlserver 并不总是执行/允许级联删除
- 在每个实体的目标继承中,级联删除是不可能的。
我们确实支持直接在数据库上批量删除。因此,您不必首先获取要删除的所有实体。例如,要删除客户订单的所有订单详细信息,请在 orderdetails 上创建直接删除,其中您指定 fieldcompareset 谓词作为过滤器,其中您根据订单中的 customerid 指定订单过滤器。然后使用相同谓词(不带联接)删除订单,然后删除客户。您可以将这些删除分组到一个工作单元中,以便更轻松地在事务中一次性运行它们。
如果您遇到此问题,请在我们的论坛上发布问题:http://www.llblgen.com/tinyforum .我们很高兴为您提供帮助
No, LLBLGen Pro doesn't support cascading deletes. We didn't build this in for the following reasons:
- it's not always possible to do cascading deletes (imagine a diamond shaped model, where two / more paths lead from a to b. This is also why for example sqlserver not always performs /allows cascade deletes
- in target-per-entity inheritance, cascade deletes is not possible.
We do support bulk deletes directly on the db. So you don't have to fetch all entities to delete first. For example, to delete all order details for the orders for the customer, create a direct delete on orderdetails where you specify as filter a fieldcompareset predicate where you specify a filter on order based on the customerid in order. Then delete the orders using the same predicate (without the join), and then delete the customer. You can group these deletes in a unit of work to run them in 1 go in a transaction easier.
If you get stuck with this, please post a question on our forums: http://www.llblgen.com/tinyforum .We're happy to help you