2016-11-01 2 views
0

Ich habe ein einfaches TodoItem Beispiel mit Offline-Synchronisierung. Alles gut. Die Konflikte werden erkannt und Client erfasst MobileServicePreconditionFailedException Ausnahme.Azure Mobile App und MobileServicePreconditionFailedException

Nun, wenn ich TableController ändern Dto Zuordnungen zu verwenden und benutzerdefinierte verwenden MappedEntityDomainManager ich nie MobileServicePreconditionFailedException Ausnahme.

Was fehlt mir?

Ich modifizierte Microsoft TodoItem Beispiel, um das Problem zu demonstrieren, also der einzige Unterschied ist DomainManager und TableController.

Sowohl DTO und Entity aus EntityData abgeleitet, so dass die zu tun haben, alle notwendigen Eigenschaften Version, UpdatedAt, etc .....

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; } 
    } 

Die SQL-Tabelle ist das gleiche wie in Microsoft Beispiel.

Wenn ich DomainManager entferne und in TableController Entity anstelle von DTOs verwende, dann ist alles in Ordnung.

Danke

die Steuerung wie folgt aussieht:

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>(); 

     } 
    } 

} 

Der mappedentity Manager sieht wie folgt aus:

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); 
     } 
    } 
} 

beide TodoItem und TodoItemDto aus EntityData abgeleitet.

+0

Wie sieht Ihr DTO aus? Hat es die Felder Version, AktualisiertAt usw.? Wie sieht die SQL-Tabelle aus? –

+0

Adrian, ich habe meine Frage mit Informationen bearbeitet. Vielen Dank – h8tow8

Antwort