Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Issue: NavigationPropertyConvention called for complex properties and breaking the model [1024]

$
0
0
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()
....
Comments: This needs to be investigated post removal of config. conventions.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>