Model view controller 外键或虚拟字段
我有一个项目表,其中一些字段指向参与者表,但所有字段的含义都不同:Model view controller 外键或虚拟字段,model-view-controller,foreign-key-relationship,Model View Controller,Foreign Key Relationship,我有一个项目表,其中一些字段指向参与者表,但所有字段的含义都不同: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace iMaSys.Models { pub
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace iMaSys.Models
{
public class Project
{
[Key]
public int ProjectID { get; set; }
[Required]
[StringLength(128)]
[Display(Name = "Omschrijving")]
public string Description { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Startdatum")]
public DateTime StartDate { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Einddatum")]
public DateTime? EndDate { get; set; }
public Boolean Active { get; set; }
[Display(Name = "Mediation Casenummer")]
public string Mediation_casenr { get; set; }
public Participant CaseManager { get; set; }
public Participant Supervisor { get; set; }
public Participant Party_1 { get; set; }
public Participant Party_2 { get; set; }
public Participant Client { get; set; }
public Participant InterventionManager { get; set; }
public Participant Mediator { get; set; }
public virtual ProjectCategorySub ProjectCategorySubject { get; set; }
}
}
现场案例经理、主管、第1方等都指向参与者。在Particpant中,我添加了反向属性来告诉框架项目和参与者之间的联系:
[InverseProperty("Mediator")]
public List<Project> ProjectMediators { get; set; }
[InverseProperty("Supervisor")]
public List<Project> ProjectSupervisors { get; set; }
etc. etc.
添加迁移和更新数据库后,项目中的字段命名如下:
CaseManager\u ParticipantID等。我只需要CaseManagerID指向参与者\u ParticipantID。我尝试了几件事,但我似乎不明白如何让它发挥作用
我被困在这个问题上了,有人能给我指出正确的方向吗
致以最诚挚的问候,Janno Hordijk我自己解决了这个问题,但想与大家分享我的发现 与会者:
[InverseProperty("Mediator")]
public virtual ICollection<Project> MediatorProjects { get; set; }
[InverseProperty("Supervisor")]
public virtual ICollection<Project> SupervisorProjects { get; set; }
现在数据库正常了,我的字段名是Supervisor\u ID而不是Supervisor\u Participant\u ID
最好的问候,Janno也许我更新了我的问题,将反向属性包括在内。有人能帮我吗?别忘了接受。
[ForeignKey("Mediator")]
public int? Mediator_ID { get; set; }
public virtual Participant Mediator { get; set; }
[ForeignKey("Supervisor")]
public int? Supervisor_ID { get; set; }
public virtual Participant Supervisor { get; set; }