pnolan
March 20th, 2009, 12:45 AM
Hi,
I have a question regarding the Entity Framework that I am hoping you could answer.
Background
I have defined a model with Table-per-Type Inheritance using the EF. For the purpose of this question let’s just say I have 2 tables, Person and PersonStatus. Person contains 3 columns Id, Name and PersonStatusId. The PersonStatus table contains 2 columns Id and Code (where code may be a value such as Single, Married, Divorced). I am aware that PersonStatus could potentially be a bit column within the Person Table but this is just an example.
My corresponding class definitions should look something like
public class Person
{
public Guid Id { get; set; }
public String Name { get; set; }
public PersonStatus PersonStatus { get; set; }
}
public class PersonStatus
{
public Guid Id { get; set; }
public String Code { get; set; }
}
As you can see Person contains a public accessor for PersonStatus however PersonStatus knows nothing about Person.
Issue
The EF model designer seems to only support the following Multiplicity
1. One
2. Zero or One
3. Many
Each of these scenarios would add a Navigation Property to both the Person class and the PersonStatus class. However my situation really represents an association of 1 to 0. Therefore I really require a multiplicity of zero.
Question
Is there a way to define my Person class and PersonStatus class as described above? So that Person contains a public PersonStatus property and PersonStatus has no reference to Person.
Thanks heaps,
Patrick
I have a question regarding the Entity Framework that I am hoping you could answer.
Background
I have defined a model with Table-per-Type Inheritance using the EF. For the purpose of this question let’s just say I have 2 tables, Person and PersonStatus. Person contains 3 columns Id, Name and PersonStatusId. The PersonStatus table contains 2 columns Id and Code (where code may be a value such as Single, Married, Divorced). I am aware that PersonStatus could potentially be a bit column within the Person Table but this is just an example.
My corresponding class definitions should look something like
public class Person
{
public Guid Id { get; set; }
public String Name { get; set; }
public PersonStatus PersonStatus { get; set; }
}
public class PersonStatus
{
public Guid Id { get; set; }
public String Code { get; set; }
}
As you can see Person contains a public accessor for PersonStatus however PersonStatus knows nothing about Person.
Issue
The EF model designer seems to only support the following Multiplicity
1. One
2. Zero or One
3. Many
Each of these scenarios would add a Navigation Property to both the Person class and the PersonStatus class. However my situation really represents an association of 1 to 0. Therefore I really require a multiplicity of zero.
Question
Is there a way to define my Person class and PersonStatus class as described above? So that Person contains a public PersonStatus property and PersonStatus has no reference to Person.
Thanks heaps,
Patrick