EF core - Best way to outline the relationship between the entities

Viewed 28

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.

  1. One zone can have multiple RackDataItem records
  2. One building can have multiple zone records
  3. 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!!

0 Answers
Related