【问题标题】:BreezeSharp Attach Property key not found未找到 BreezeSharp 附加属性键
【发布时间】:2017-12-19 15:43:35
【问题描述】:

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

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

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

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 时,我可以看到所有实体类的自定义映射。

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

【问题讨论】:

    标签: breeze breeze-sharp


    【解决方案1】:

    好的。那很奇怪。

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

    更新

    我继续并开始删除 Breezesharp。 Breezesharp 项目不是最新的,并且与 Xamarin 没有很好的集成。如果您对您的体验提出任何意见,我们将不胜感激。

    【讨论】:

    • 问题是因为我使用非 Breezesharp 模式创建了实体类。获取值,设置值。
    猜你喜欢
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    相关资源
    最近更新 更多