EF 5.0 Multiplicity error with simple matching

I have the following domain objects:

public class Person 
{
    public int Id {get; set;}
    public int? FatherId {get; set;}
    public int? MotherId {get; set;}
    public int? HomeChurchId {get; set;}
    public int? BirthCountryId {get; set;}

    public Parent Father {get; set;}
    public Parent Mother {get; set;}
    public Church HomeChurch {get; set;}
    public Country BirthCountry {get; set;}
}

public class Parent
{
    public int Id {get; set;}
    ...
}

public class Church
{
    public int Id {get; set;}
    ...
}

public class Country
{
    public int Id {get; set;}
    ...
}

When matching Person, all of these properties appear in much the same way:

HasOptional(p => p.Father).WithMany().HasForeignKey(p => p.FatherId);
HasOptional(p => p.BirthCountry).WithMany().HasForeignKey(p => p.BirthCountryId);    
...

The problem is that with BirthCountry I get the following error when trying to request Person:

One or more validation errors were detected during model generation:

System.Data.Entity.Edm.EdmAssociationType: : Multiplicity conflicts with the
referential constraint in Role 'Person_BirthCountry_Target' in relationship
'Person_BirthCountry'. Because all of the properties in the Dependent Role are 
non-nullable, multiplicity of the Principal Role must be '1'.

If I remove the BirthCountry property (and display), everything will work fine. What confuses me is that BirthCountry is set up just like any other nullable property in Person. Why don't other properties give me the same error?

Thanks for any help you can offer!

+5
source share
1 answer

Ignorance is not bliss ... it just upsets him.

- , [] BirthCountryId. ... . EF, .

, - , .

+11

All Articles