1

I'm implementing an application with Breezesharp. I ran into a issue when insert the entity in the EntityManager. The error is:

There are no KeyProperties yet defined on EntityType: 'TransportReceipt:#Business.DomainModels'

I already faced this error with my first entity type "Customer" and implement a mismatching approach as suggested here. In that case I made the get operation against my WebApi with success. But now I'm creating the TransportReceipt entity inside my application.

Mapping mismatch fix

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

My base dataservice core code

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

This is who I'm trying to add the new entity

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

When I try to add add the entity to the EntityManager, I can see the custom mapping for all my entity classes. enter image description here

So my question is what I'm doing wrong.

1 Answers1

0

Ok. That was weird.

I changed the mapping for a new fake int property and works. I'll test the entire save flow soon and I'll share the result here.

Update

I moved on and start removing Breezesharp. The Breezesharp project is no up-to-date and doesn't have good integration with Xamarin. I'll appreciate any comment with your experience.