Okay, everyone?
I have the following problem: I have two Person and Property classes that may have an address, but the < strong> Person can have 0: N Address and Property 0: 1 . Knowing this I've transformed the Address class into abstract and created two other classes that inherit the attributes of it,Afterthismodeling,IcreatedtheAddress,AddressPersonandAddressPropertyclassesasfollows:
[Table("ADDRESSES")]
public abstract class Address
{
[Key]
public int AddressId { get; set; }
[MaxLength(200)]
public string Street { get; set; }
[MaxLength(10)]
public string ZipCode { get; set; }
[MaxLength(6)]
public string Number { get; set; }
[MaxLength(100)]
public string Neighborhood { get; set; }
[MaxLength(100)]
public string City { get; set; }
[MaxLength(100)]
public string State { get; set; }
[MaxLength(100)]
public string Complement { get; set; }
public StatusAddressEnum.StatusAddress Status { get; set; }
public KindAddressEnum.KindAddress KindAddress { get; set; }
}
[Table("ADDRESSES_PERSONS")]
public class AddressPerson : Address
{
public AddressPerson()
{
KindAddress = KindAddressEnum.KindAddress.PERSON;
}
[ForeignKey("Person")]
public int PersonId { get; set; }
public virtual Person Person { get; set; }
}
[Table("ADDRESS_PROPERTIES")]
public class AddressProperty : Address
{
public AddressProperty()
{
KindAddress = KindAddressEnum.KindAddress.PROPERTY;
}
[Key, ForeignKey("Property")]
public int PropertyId { get; set; }
public virtual Property Property { get; set; }
}
When trying to create a migration I have the following error: AddressProperty_Property_Source:: Multiplicity is not valid in Role 'AddressProperty_Property_Source' in relationship 'AddressProperty_Property'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be ''. *
If I remove the AddressId attribute from the Address class and move on to AddressPerson , EF complains that the Address does not have a Key . What would be the correct way to solve this problem?