首页 > 解决方案 > 多选与 3 个表具有 3 个多对多关系的类

问题描述

我有 4 个类,其中 3 个与主要的 Person 具有多对多关系。如何为 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
}

标签: c#asp.net-mvcentity-framework

解决方案


推荐阅读