I want to create a direct relation between the Task entity and the child entities, to get with the task the corresponding child and when I get the child to get the corresponding task.
I have an entity named Task and I need to relate it with other entities types one2one. My solution was to create in the task entity one propriety for the child id and one for the child type:
public class Task
{
public int Id { get; set; }
public int ChildId { get; set; }
public int TaskTypeId { get; set; }
public Child1 Child1{ get; set; }
public Child2 Child2{ get; set; }
}
public class Child1
{
public int Id { get; set; }
public Task Task{get; set;}
}
public class Child2
{
public int Id { get; set; }
public Task Task {get; set;}
}
The properties of
Child1andChild2classes are the same, why did you create 2 separate classes? Wouldn't it work to do it this way with a single class?