具有3个表的3对多关系的类的multiselect

时间:2019-01-11 08:11:58

标签: c# asp.net-mvc entity-framework

我有4个课程,其中3个与主要的Person具有多对多关系。如何为Person创建一个多选下拉菜单,以从书籍,课程和会议列表中进行选择?人员类具有书籍列表,课程列表和会议列表,因为一个人可以拥有多个以上的每个课程。书籍,课程和会议也是如此。这些课程中的每一个都有一个人员列表,因为一本书可以有多个作者,一个班级可以有多个讲师,而一个会议可以有多个参加者。我不确定如何做到这一点以及如何将表相互链接。任何帮助都感激不尽。我先使用实体​​框架代码。

这是我的课程:

public class Workshop
{
    public Workshop()
    {
        Customers = new HashSet<Customer>();
    }

    [Key]
    public int WorkshopID { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public Session sessions { get; set; }

    public virtual ICollection<Customer> Customers { get; set; }
}

public enum Session
{
    NewWorkshopPanels,
    Workshops,
    PanelSessions
}


  public class Paper
   {
       public Paper()
       {
        Customers = new HashSet<Customer>();            
    }


    [Key]
    public int PaperID { get; set; }

    [DisplayName("Short Title")]
    public string ShortTitle { get; set; }

    [DisplayName("Paper Title")]
    public string Title { get; set; }

    [DisplayName("Description")]
    public string Description { get; set; }

    [DisplayName("Published Date")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]        
    public DateTime? PublishedDate { get; set; }

    [DisplayName("Date Created")]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]        
    [DataType(DataType.Date)]
    public DateTime? CreateDate { get; set; }

    [DisplayName("Due Date")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]        
    public DateTime? DueDate { get; set; }

    [DisplayName("Image Title")]
    public string imgTitle { get; set; }

    [DisplayName("Image")]
    public string imgPath { get; set; }

    [NotMapped]
    public HttpPostedFileBase ImageFile { get; set; }

    public virtual ICollection<Customer> Customers { get; set; }
    public virtual ICollection<FileUsed> Files { get; set; }
}


public class Conference
    {
        public Conference()
        {
        Customers = new HashSet<Customer>();
    }

    [Key]
    public int ConferenceID { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }

    [DisplayName("Start Date")]
    [DataType(DataType.Date)]        
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]       
    public DateTime? StartDate { get; set; }

    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]        
    public DateTime? EndDate { get; set; }

    [DataType(DataType.Time)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh\\:mm}")]
    public TimeSpan? StartTime { get; set; }

    [DataType(DataType.Time)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh\\:mm}")]
    public TimeSpan? EndTime { get; set; }

    public virtual ICollection<Customer> Customers { get; set; }
    public virtual ICollection<FileUsed> Files { get; set; }
}

 public class Customer
    {
        public Customer()
        {
        paper = new HashSet<Paper>();
        workshop = new HashSet<Workshop>();
        conference = new HashSet<Conference>();
    }


    [Key]
    public int CustomerID { get; set; }
    [DisplayName("First Name")]
    public string FirstMidName { get; set; }

    [DisplayName("Last Name")]
    public string LastName { get; set; }

    [DisplayName("Short Title")]
    public string ShortTitle { get; set; }

    [DisplayName("Title")]
    public string Title { get; set; }

    [DisplayName("Biography")]
    public string Bio { get; set; }

    public string Company { get; set; }

    public bool? IsHallFame { get; set; }


    [DisplayName("Hall of Fame Date")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]        
    public DateTime? HallOfFameDate { get; set; }
    public bool? IsInstructor { get; set; }
    public bool? IsTechnicalCommittee { get; set; }
    public bool? IsAuthor { get; set; }

    [DisplayName("Full Name")]
    public string FullName
    {
        get { return FirstMidName+"  " +LastName; }
    }

    //public int? conferenceID { get; set; }
    //public int? PaperID { get; set; }
    //public int? WorkshopID { get; set; }

    public CustomerRole customerRole { get; set; }

    //public virtual Conference conference { get; set; }
    //public virtual Workshop workshop { get; set; }
    //public virtual Paper paper { get; set; }


    public virtual ICollection<Conference> conference { get; set; }
    public virtual ICollection<Workshop> workshop { get; set; }
    public virtual ICollection<Paper> paper { get; set; }


    public virtual ICollection<FileUsed> Files { get; set; }


}

public enum CustomerRole
{
    Speaker = 1,
    Attendant = 2
}

0 个答案:

没有答案