如何使用Breeze JS执行逻辑删除? [英] How to perform logical delete with Breeze JS?

查看:239
本文介绍了如何使用Breeze JS执行逻辑删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用Breeze JS执行逻辑/软删除?

How do I perform logical/soft delete with Breeze JS?

很明显,对我来说,这取决于我的数据模型如何实现逻辑删除(状态= 2),那么我会检测到我的实体是否以某种方式在Breeze Controller中被标记为删除,然后将其更改为具有列更改的Update,或者什么是首选做法?

Obviously it would depend on my data model in how I implement my logical delete, for me (Status=2), so would I detect that my entity is marked for deletion in the Breeze Controller somehow and convert it into an Update with my column change, or what is the preferred practice?

这说明了我认为如何执行物理删除,但不执行逻辑删除。
http://www.breezejs.com/documentation/inside-entity#DeleteEntity

This explains how to perform a physical delete I believe, but no logical delete. http://www.breezejs.com/documentation/inside-entity#DeleteEntity

推荐答案

您的建议可能会起作用,但是我的第一步是简单地添加 softDelete 到您的客户端类的方法,该方法只是将状态设置为 2 。我还将在服务器上的每个查询中添加一个 where Status!= 2条件,以便默认情况下不会返回已删除的实体,例如:

Your suggestion would likely work, but my first pass at this would simply be to add a softDelete method to your client side class that simply sets the status to 2. I would also add a 'where Status!=2' condition to each query on the server so that by default no deleted entities get returned, something like:

[HttpGet]
public IQueryable<Customer> Customers(bool includedDeleted) {
   if (includeDeleted) {
     return ContextProvider.Context.Customers;
   } else {
     return ContextProvider.Context.Customers.Where(c = c.Status != 2);
   }
} 

进一步的改进是自动分离所有<$调用 SaveChanges 后,客户端上的c $ c> soft删除了实体。即迭代已保存的实体,并使用 status == 2

A further refinement would be to automatically detach any soft deleted entities on the client after a SaveChanges call. i.e. iterate over the 'saved' entities and detach any with a status == 2

分离任何实体,希望这是有道理的。

Hope this makes sense.

这篇关于如何使用Breeze JS执行逻辑删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆