2017-07-14 102 views
1

我正在執行與Breezesharp應用程序。在EntityManager中插入實體時遇到問題。錯誤是:BreezeSharp附加屬性鍵未找到

有沒有上的EntityType尚未定義KeyProperties:「TransportReceipt:#Business.DomainModels」

我已經遇到這個錯誤我的第一個實體類型的「客戶」,實行不匹配方法建議here。在那種情況下,我成功地對我的WebApi進行了get操作。但是現在我在我的應用程序中創建了TransportReceipt實體。

映射錯配修復

public static class ExtendMap 
{ 
    private static bool? executed; 
    public static void Execute(MetadataStore metadataStore) { 
     if (ExtendMap.executed == true) 
     { 
      return; 
     } 

     var customerBuilder = new EntityTypeBuilder<Customer>(metadataStore); 
     customerBuilder.DataProperty(t => t.id).IsPartOfKey().IsAutoIncrementing(); 

     var transportReceiptBuilder = new EntityTypeBuilder<TransportReceipt>(metadataStore); 
     transportReceiptBuilder.DataProperty(t => t.id).IsPartOfKey().IsAutoIncrementing(); 

     var transportReceiptAttachmentBuilder = new EntityTypeBuilder<TransportReceiptAttachment>(metadataStore); 
     transportReceiptAttachmentBuilder.DataProperty(t => t.id).IsPartOfKey().IsAutoIncrementing(); 

     var uploadedFileBuilder = new EntityTypeBuilder<UploadedFile>(metadataStore); 
     uploadedFileBuilder.DataProperty(t => t.id).IsPartOfKey().IsAutoIncrementing(); 

     ExtendMap.executed = true; 
    } 
} 

我的基本DataService的核心代碼

public abstract class SimpleBaseDataService 
{ 
    public static string Metadata { get; protected set; } 
    public static MetadataStore MetadataStore { get; protected set; } 
    public string EntityName { get; protected set; } 
    public string EntityResourceName { get; protected set; } 
    public EntityManager EntityManager { get; set; } 
    public string DefaultTargetMethod { get; protected set; } 

    static SimpleBaseDataService() 
    { 
     try 
     { 
      var metadata = GetMetadata(); 
      metadata.Wait(); 
      Metadata = metadata.Result; 

      MetadataStore = BuildMetadataStore(); 

     } 
     catch (Exception ex) 
     { 
      var b = 0; 
     } 
    } 


    public SimpleBaseDataService(Type entityType, string resourceName, string targetMethod = null) 
    { 
     var modelType = typeof(Customer); 
     Configuration.Instance.ProbeAssemblies(ConstantsFactory.BusinessAssembly); 
     try 
     { 
      this.EntityName = entityType.FullName; 
      this.EntityResourceName = resourceName; 

      this.DefaultTargetMethod = (string.IsNullOrWhiteSpace(targetMethod) ? "GetAllMobile" : targetMethod); 

      var dataService = new DataService($"{ConstantsFactory.Get.BreezeHostUrl}{this.EntityResourceName}", new CustomHttpClient()); 
      dataService.HasServerMetadata = false; 


      this.EntityManager = new EntityManager(dataService, SimpleBaseDataService.MetadataStore); 
      this.EntityManager.MetadataStore.AllowedMetadataMismatchTypes = MetadataMismatchTypes.AllAllowable; 
      // Attach an anonymous handler to the MetadataMismatch event 
      this.EntityManager.MetadataStore.MetadataMismatch += (s, e) => 
      { 
       // Log the mismatch 
       var message = string.Format("{0} : Type = {1}, Property = {2}, Allow = {3}", 
              e.MetadataMismatchType, e.StructuralTypeName, e.PropertyName, e.Allow); 

       // Disallow missing navigation properties on the TodoItem entity type 
       if (e.MetadataMismatchType == MetadataMismatchTypes.MissingCLRNavigationProperty && 
        e.StructuralTypeName.StartsWith("TodoItem")) 
       { 
        e.Allow = false; 
       } 
      }; 

     } 
     catch (Exception ex) 
     { 
      var b = 0; 
     } 
    } 
} 

這是誰我想添加新的實體

//DataService snippet 
public void AttachEntity(T entity) 
    { 
     this.EntityManager.AttachEntity(entity, EntityState.Added); 
    } 

//Business 
this.TransportReceipt = new TransportReceipt { id = Guid.NewGuid(), date = DateTime.Now, customerId = Customer.id/*, customer = this.Customer*/ }; 
      this.Attachments = new List<TransportReceiptAttachment>(); 
      this.TransportReceipt.attachments = this.Attachments; 
      TransportReceiptDataService.AttachEntity(this.TransportReceipt); 

當我嘗試添加將實體添加到EntityManager中,我可以看到所有實體類的自定義映射。 enter image description here

所以我的問題是我做錯了什麼。

回答

0

好的。那很奇怪。

我改變了一個新的假的int屬性的映射,並工作。我會盡快測試整個保存流程,我會在這裏分享結果。

更新

我提出並開始刪除Breezesharp。 Breezesharp項目不是最新的,與Xamarin沒有很好的集成。我會感謝您的任何意見與您的經驗。

+0

問題是因爲我創建的實體類不使用Breezesharp模式。 GetValue,SetValue。 –