私は、オフラインシンクで簡単なTodoItemの例を持っています。 ALlはうまくいく。 競合が検出され、クライアントがキャッチしますMobileServicePreconditionFailedException例外。晴れのモバイルアプリとMobileServicePreconditionFailedException
Dtoマッピングを使用してカスタムMappedEntityDomainManagerを使用するようにTableControllerを変更すると、MobileServicePreconditionFailedException例外が発生します。
私には何が欠けていますか?
私は問題を示すためにMicrosoft TodoItemサンプルを修正しました。したがって、唯一の違いはDomainManagerとTableControllerです。
public class TodoItemDto : EntityData
{
public string Text { get; set; }
public bool Complete { get; set; }
public bool bWorks { get; set; }
}
public class TodoItem : EntityData
{
public string Text { get; set; }
public bool Complete { get; set; }
}
SQLテーブルは、Microsoftの例と同じである..... DTOおよびエンティティの両方がEntityData由来するので、ザは、すべての必要な特性等版、UpdatedAtを持っています。
DomainManagerを削除し、DTOの代わりにTableController Entityで使用すると、すべてが良好です。
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.OData;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.Azure.Mobile.Server;
using TimeCardSyncSrv.DataObjects;
using TimeCardSyncSrv.Models;
namespace TimeCardSyncSrv.Controllers
{
public class TodoItemController : TableController<TodoItemDto>
{
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
MobileServiceContext context = new MobileServiceContext();
DomainManager = new TodoItemMappedEntityDomainManager(context, Request);
}
// GET tables/TodoItem
public IQueryable<TodoItemDto> GetAllTodoItems()
{
return Query();
}
// GET tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public SingleResult<TodoItemDto> GetTodoItem(string id)
{
return Lookup(id);
}
// PATCH tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public Task<TodoItemDto> PatchTodoItem(string id, Delta<TodoItemDto> patch)
{
return UpdateAsync(id, patch);
}
// POST tables/TodoItem
public async Task<IHttpActionResult> PostTodoItem(TodoItemDto item)
{
TodoItemDto current = await InsertAsync(item);
return CreatedAtRoute("Tables", new { id = current.Id }, current);
}
// DELETE tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public Task DeleteTodoItem(string id)
{
return DeleteAsync(id);
}
public static void AddMap(IConfiguration cfg)
{
cfg.CreateMap<TodoItem, TodoItemDto>();
cfg.CreateMap<TodoItemDto, TodoItem>();
}
}
}
mappedentityマネージャは次のようになります:
は、コントローラは次のようになりますあなたの
ありがとう
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.OData;
using Microsoft.Azure.Mobile.Server;
using TimeCardSyncSrv.DataObjects;
using TimeCardSyncSrv.Models;
namespace TimeCardSyncSrv.Controllers
{
public class TodoItemMappedEntityDomainManager
: MappedEntityDomainManager<TodoItemDto, TodoItem>
{
public TodoItemMappedEntityDomainManager(DbContext context,
HttpRequestMessage request)
: base(context, request)
{
}
public override SingleResult<TodoItemDto> Lookup(string id)
{
return this.LookupEntity(p => p.Id == id);
}
public override Task<TodoItemDto> UpdateAsync(string id, Delta<TodoItemDto> patch)
{
return this.UpdateEntityAsync(patch, id);
}
public override Task<bool> DeleteAsync(string id)
{
return this.DeleteItemAsync(id);
}
}
}
TodoItemとTodoItemDto両方EntityData由来しています。私の本の中でMappedEntityDomainManagerため
あなたのDTOはどのように見えますか? Version、UpdatedAtなどのフィールドはありますか? SQLテーブルはどのように見えますか? –
Adrian、私は情報で私の質問を編集しました。ありがとうございました – h8tow8