MappingConfiguration class per entity and complex types?

Thread is closed for posting
3 posts, 0 answers
  1. Diego
    Diego avatar
    8 posts
    Member since:
    May 2012

    Posted 31 Aug 2013 Link to this post

    I'm sure i'm missing something pretty silly here but I keep getting the following error... please help.. Also, how do you map complex types?

    This is against the northwind sample db..

    System.MissingFieldException : There is no field with name 'CustomerID' backing 'Id' property in type 'MMG.Core.Testing.Integration.Northwind.Customer'. You need to either change the Field Naming rules of the mapping configuration object or call HasFieldName(string) with the name of the backing field.

    public class CustomerOAMapping : MappingConfiguration<Customer>
            public CustomerOAMapping()

                HasProperty(p => p.Id).HasFieldName("CustomerID").IsIdentity().HasLength(5);
                HasProperty(p => p.Name).HasFieldName("CompanyName").HasLength(40).IsNullable();

                //contact complex
                HasProperty(p => p.Contact.Name).HasFieldName("ContactName").HasLength(30);
                HasProperty(p => p.Contact.Title).HasFieldName("ContactTitle").HasLength(30);
                HasProperty(p => p.Contact.Phone).HasFieldName("Phone").HasLength(24);
                HasProperty(p => p.Contact.Fax).HasFieldName("Fax").HasLength(24);

                //address complex
                HasProperty(p => p.Contact.Address.Street).HasFieldName("Address").HasLength(60);
                HasProperty(p => p.Contact.Address.City).HasFieldName("City").HasLength(15);
                HasProperty(p => p.Contact.Address.Region).HasFieldName("Region").HasLength(15);
                HasProperty(p => p.Contact.Address.PostalCode).HasFieldName("PostalCode").HasLength(60);
                HasProperty(p => p.Contact.Address.Country).HasFieldName("Country").HasLength(15);

  2. Diego
    Diego avatar
    8 posts
    Member since:
    May 2012

    Posted 03 Sep 2013 Link to this post

    It may be related to this -

  3. Kristian Nikolov
    Kristian Nikolov avatar
    206 posts

    Posted 04 Sep 2013 Link to this post

    Hello Diego,

    Most probably the reason for the error you are getting is incorrect field name passed to the HasFieldName() extension method. This method requires the name of the field which is accessed through the property specified in the HasProperty() method. So in your case you must pass the actual name of field accessed through the Id property.

    Note that after fixing the field names, your code will still result in an error due to the fact that  OpenAccess will search the fields of Contact and Address in the Customer class. You can however take advantage of our struct support and define Address and Contact as structures. This is the OpenAccess ORM feature that matches the Entity Framework Complex Types support. I have attached a sample project illustrating how to map Customer class that has properties of types Address and Contact which are defined as structures. With this approach however, the Address and Contact objects will not be persistent, they will be used solely to organize the data contained within Customer objects. Please note that in order to run the project you will need to upgrade the project references and change the connection strings located in both app.config files.

    In case you wish to persist Address and Contact, you may try to organize your classes in a hierarchy and use Flat Inheritance, with which all types in the hierarchy are mapped to the same table.

    I hope the provided information will help you with your scenario.

    Kristian Nikolov
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Back to Top