2016-11-01 2 views
0

오프라인 동기화가있는 간단한 TodoItem 예제가 있습니다. ALl은 잘 작동합니다. 충돌이 감지되고 클라이언트가 catch합니다. 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 테이블은 마이크로 소프트 예에서와 동일하다 ..... 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에 대한

+0

DTO는 어떤 모습입니까? Version, UpdatedAt 등의 필드가 있습니까? SQL 테이블은 어떻게 생겼습니까? –

+0

애드리안, 내 질문에 대한 정보를 편집했습니다. 고맙습니다 – h8tow8

답변

관련 문제