0
All right, guys?
I have the following problem: I have two classes Person and Property who may have an address (Address), but the class Person may have 0:N Address and the Property 0:1. Knowing that I transformed the class Address in abstract and created two other classes that inherit her attributes, as print below.
After this modeling, I created the classes Address, Addressperson and Addressproperty as follows:
[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 attribute Addressid class Address and move on to the Addressperson, the RU claims that the class Address does not possess a Key. What would be the right way to solve this problem?
I think the relationship is too many for many! ??? kind
Person
andAddress
generates a tablePersonAddress
in the same logic withProperty
, good at least I think ... !!!– novic
@Virgilionovic is correct the modeling, an address(Address) belongs to only one person (Person) or a property(Property).
– Tainã Milano