I have a zone entity having columns that look like as below,
public class Zone
{
[Key]
public Guid ZoneId { get; set; }
public string Name { get; set; }
public RackData RackData {get; set;}
}
I have another entity, RackDataItem, and the structure that looks as below.
public class RackDataItem
{
[Key]
public Guid RackDataItemId { get; set; }
public DateTime RackDataItemBillDateTimeUTC { get; set; }
public RackData RackData{ get; set; }
}
Another entity RackData as well,
public class RackData
{
[Key]
public Guid RackDataId { get; set; }
[ForeignKey("Building")]
public Guid BuildingId { get; set; }
public virtual Building Building { get; set; }
public ICollection<RackDataItem> RackDataItems { get; set; }
public ICollection<Zone> ZoneData { get; set; }
}
So, I do have the below relationships that I need to consider.
- One zone can have multiple RackDataItem records
- One building can have multiple zone records
- Here RackData table acts as a mediator between Zones and rackdataitem entities
With the above conditions, I made the above entities structure. Since I am new to this, I am unsure whether I outlined the proper relationship among those entities.
Could anyone please let me know whether those entity relations are properly outlined or not?
Many thanks in advance!!
CodePudding user response:
This is your Database Diagram look like
I have to add the Building table
One zone can have multiple RackDataItem records
if you want RackDataItem to have a relation with Zone is weird, they both many to one with RackData. In your Models they share no key but it is possible to manage many Zone via RackDataId in the RackDataItems table
One building can have multiple zone records
Not necessary, one Building can have many RackData, one RackData can have many Zone, one RackData also can have many RackDataItem
Here RackData table acts as a mediator between Zones and rackdataitem entities
So the Building is the highest Hierarchy