c# - 多选与 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
}
解决方案
推荐阅读
- tfs - 用户向 TFS 构建代理添加功能所需的最低权限是什么
- javascript - 循环遍历图层并将它们设置为可见
- vba - MS Access '16 - 查询不从字段中提取值
- batch-file - 使用 youtube-dl 下载视频并使用 FFmpeg 转换的批处理脚本
- typescript - 为什么 Typescript 在尝试使用函数的结果执行操作时会引发转换错误?
- excel - 如何自动调整评论框的大小以适应其内容?
- android - Android API 28 上 ACTION_SHUTDOWN 的替代方案
- fullcalendar - v3 中的 Fullcalendar groupId 事件对象
- r - 为什么我会收到错误消息:dffits 的参数长度为 0?
- windows-authentication - 尝试获取用户凭据以通过 ProxyPass