Model
```
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
```
Convention:
```
public class NavigationPropertyConfigurationConvention
: IConfigurationConvention<PropertyInfo, NavigationPropertyConfiguration>
{
public void Apply(
PropertyInfo propertyInfo,
Func<NavigationPropertyConfiguration> configuration)
{
// TODO: if you comment this out the exception is gone
configuration();
}
}
```
Navigation property convention is called for the complex property which may result in configuring the related complex type as an entity which in turn causes an exception:
Unhandled Exception: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
\tConsoleApplication20.Address: : EntityType 'Address' has no key defined. Define the key for this EntityType.
\tAddresses: EntityType: EntitySet 'Addresses' is based on type 'Address' that has no keys defined.
at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
....
```
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
```
Convention:
```
public class NavigationPropertyConfigurationConvention
: IConfigurationConvention<PropertyInfo, NavigationPropertyConfiguration>
{
public void Apply(
PropertyInfo propertyInfo,
Func<NavigationPropertyConfiguration> configuration)
{
// TODO: if you comment this out the exception is gone
configuration();
}
}
```
Navigation property convention is called for the complex property which may result in configuring the related complex type as an entity which in turn causes an exception:
Unhandled Exception: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
\tConsoleApplication20.Address: : EntityType 'Address' has no key defined. Define the key for this EntityType.
\tAddresses: EntityType: EntitySet 'Addresses' is based on type 'Address' that has no keys defined.
at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
....