简体   繁体   中英

Modelling two one-to-many relationships as one

I am not sure what the name for the following concept is, which is problematic as I am trying to implement it in my Entity Framework domain model (my reputation is not high enough to post images, even though it would be useful!):

Permit -- has many --> OfficePermit -- has many --> Task

Essentially this is a one-to-many relationship between Permit and Task and I would like to represent it with a collection navigation property ICollection<Task> Tasks on my Permit domain model.

I am not interested in implementing this in a ViewModel layer as an extra property since I am relying on metadata generated by entity framework for use on the client side (using Breeze.js). How would I go about representing this relationship in my domain model - is it even possible?

You can do it like this...

public class Permit
{
    public Permit()
    {
        this.PermitId = Guid.NewGuid().ToString();
    }

    public string PermitId { get; set; }

    public ICollection<OfficePermit> OfficePermits { get; set; }
}

public class OfficePermit   
{
    public OfficePermit()
    {
        this.OfficePermitId = Guid.NewGuid().ToString();
    }

    public string OfficePermitId { get; set; }

    public string PermitId { get; set; }

    public Permit Permit { get; set; }

    public ICollection<@Task> Tasks { get; set; }
}

public class @Task
{
    public Task()
    {
        this.TaskId = Guid.NewGuid().ToString();
    }

    public string TaskId { get; set; }

    public OfficePermit OfficePermit { get; set; }

    public string OfficePermitId { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM