sách gpt4 ai đã đi

Các vấn đề/thực hành xóa mềm dịch vụ di động Azure

In lại 作者:行者123 更新时间:2023-12-03 00:14:53 29 4
mua khóa gpt4 Nike

打开软删除后,我在客户端上添加一条记录,推送,删除添加的记录推送,然后尝试使用与初始记录相同的主键添加新记录(然后推送),我得到一个异常(exception)。 EntityDomainManager 似乎只是尝试执行新插入,而不检查记录是否要“更新”而不是插入。

但是,如果我在域管理器构造函数中关闭软删除,则一切正常。

我们正在使用增量同步,因此据我所知,需要软删除才能完成这项工作,因此我们最终不会得到移动设备和服务器之间正确情况的不同图片。

什么时候推荐采用这种方法?自定义 EntityDomainManager(或其他 DomainManager)?如果是这样,这对于更清楚地了解表 Controller 和域管理器之间的交互将很有用。

我已经构建了这个自定义域管理器,它似乎可以工作,但希望得到任何指导/建议。

public class CustomEntityDomainManager : EntityDomainManager where TData : class, ITableData
{

public CustomEntityDomainManager(DbContext context, HttpRequestMessage request, ApiServices services)
: base(context, request, services)
{
}

public CustomEntityDomainManager(DbContext context, HttpRequestMessage request, ApiServices services, bool enableSoftDelete) : base(context, request, services, enableSoftDelete)
{
}

public async override Task InsertAsync(TData data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}

// now then, if we have soft delete enabled & data has been provided with an id in it
if (EnableSoftDelete && data.Id != null)
{
// now look to see if the record exists and if it is deleted
// if so we look to remove the record before then attempting the insert

// record old value of deleted, since need to query to see if deleted.
var oldIncludeDeleted = IncludeDeleted;

thử
{
IncludeDeleted = true;
var existingData = await this.Lookup(data.Id).Queryable.FirstOrDefaultAsync();

// if record exists, and its soft deleted then truly delete it
if (existingData != null && existingData.Deleted)
{
// now need to remove this record...
this.Context.Set().Remove(existingData);
}
}
Cuối cùng
{
IncludeDeleted = oldIncludeDeleted;
}
}

if (data.Id == null)
{
data.Id = Guid.NewGuid().ToString("N");
}

return await base.InsertAsync(data);
}

1 Câu trả lời

此行为是设计使然 - 我们要求您在执行更新之前执行显式取消删除。

您提供的解决方案很好。您还可以将代码移至表 Controller ,假设您只需要在一个表中执行此行为。如果您需要在多个表中使用它,那么自定义域管理器是最好的方法。

关于Azure 移动服务软删除问题/实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26905207/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com