I know that I can solve this by clicking everything on a single entity, and not imposing complex types (since they are only 1-1 mappings), but I like the way of grouping properties in the generated OM.
I have a Customer object that contains the add-on type "CrmData". The CrmData object has a complex address type.
public class Customer { [Required] public CrmSpecificData CrmData { get; set; } } [ComplexType] public class CrmSpecificData { [MaxLength(40)] public string FirstName { get; set; } [MaxLength(80)] public string LastName { get; set; } public Address Address { get; set; } } [ComplexType] public class Address { [MaxLength(150)] public string Address1 { get; set; } [MaxLength(150)] public string Address2 { get; set; } [MaxLength(100)] public string City { get; set; } [MaxLength(15)] public string PostalCode { get; set; } public StateProvince StateOrProvince { get; set; } public virtual CountryRegion CountryOrRegion { get; set; } }
The StateProvince and CountryRegion types are objects in my database (similar to how DB DB AdventureWorks works). The problem is that when EF tries to create a model, it fails:
The type "MyCo.Crm.Entities.StateProvince" is already configured as an object type. It cannot be reconfigured as a complex type.
I tried to make StateProvince a complex type, but this does not solve the problem. Ideas?
public class StateProvince { [Key] public int StateProvinceId { get; set; } [MaxLength(3)] public string StateProvinceCode { get; set; } [MaxLength(50)] public string Name { get; set; } }
Andrew Connell
source share