1

我正在用 Breezesharp 实现一个应用程序。在 EntityManager 中插入实体时遇到问题。错误是:

EntityType 上尚未定义 KeyProperties:'TransportReceipt:#Business.DomainModels'

我的第一个实体类型“客户”已经遇到了这个错误,并按照这里的建议实施了不匹配的方法。在那种情况下,我成功地对我的 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;
    }
}

我的基础数据服务核心代码

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 时,我可以看到所有实体类的自定义映射。 在此处输入图像描述

所以我的问题是我做错了什么。

4

1 回答 1

0

好的。那很奇怪。

我更改了一个新的假 int 属性的映射并且工作正常。我将很快测试整个保存流程,并在这里分享结果。

更新

我继续前进并开始删除 Breezesharp。Breezesharp 项目不是最新的,并且与 Xamarin 没有很好的集成。对于您的经验,我将不胜感激。

于 2017-07-15T10:11:07.603 回答