I'm trying to develop a data model for c# .net Core application using Entity Framework Code first.
What I basicaly have is a data model bellow.
There are tables Dog and Person. They each contain different information. For example I can have different type of dogs. Person can have something specific and that would be not applicable for dogs.
There is 1:1 relation between Person and Item. The same relation is between Dog and Item.
In addition to that table ItemReference contains child-parent relations between Items. For example there is child - parent relation between dog and person (dog owner - dog or persons may be siblings)
I need to make alphabetical list of dogs and persons (mix them up).In addition I need to be able to get to Details page for each of the following.
Using this feels really stupid as there might be more tables in the future. For Example Cat or Car and I would need to rework these If statements each time.
@foreach (var x in Model.Item.OrderBy(y=>y.ItemName))
{
if (x.ItenType == "Dog")
{
<li><a asp-page="DogDetails" asp-route-id="@x.Item.Dog.Id">@x.ItemName</a></li>
}
if (x.ItenType == "Person")
{
<li><a asp-page="PersonDetails" asp-route-id="@x.Item.Person.Id">@x.ItemName</a></li>
}
}
Anyone knows how to make such a data model so it is more intelligent design?
Any help greatly appreciated
Tables Dog, Person and Item will look like this:
Dog
Id DogName DogTypeId DogStatusId ItemId
1 "Alex" 1 1 1
2 "Rex" 2 1 2
Person
Id PersonName PersonStatusId ItemId
1 "Joe" 1 3
2 "Jane" 2 4
Item
Id ObjectName ItemType
1 "Alex" "Dog"
2 "Rex" "Dog"
3 "Joe" "Person"
4 "Jane" "Person"
