在一个表中与UserId的多个关系

时间:2014-03-24 01:08:46

标签: model-view-controller ef-code-first entity-framework-5 visual-studio-2013 relationships

我有一个UserProfile和UserId。我需要创建一个表记分卡的关系,其中有多个列需要与UserId建立关系。它们是ScorerId,CreatedById,AgentId,ModifiedById,PublishedById ....

我不确定如何通过代码第一种方法使用mvc 4和实体5来完成这项工作?

任何帮助都将不胜感激。

public class ScorecardsModel
{
    [Key]
    public int ScorecardId { get; set; }
    [Required]
    [Display(Name = "Agent ID")]
    public int AgentId { get; set; }
    [Required]
    [Display(Name = "Agent Name")]
    public string AgentName { get; set; }
    [Display(Name = "Department")]
    public int DepartmentId { get; set; }
    [Required]
    public DateTime? CreatedOn { get; set; }
    [Required]
    [Display(Name = "Scorer")]
    public int CreatedById { get; set; }
    [Required]
    [Display(Name = "Call")]
    public int CallNum { get; set; }
    [Required]
    [Display(Name = "Call Date/Time")]
    public DateTime? CallDateTime { get; set; }
    [Required]
    [Display(Name = "Procedural Score")]
    [Range(0, 100)]
    public int ProceduralScore { get; set; }
    [Required]
    [Display(Name = "Soft Skills Score")]
    [Range(0, 100)]
    public int SoftSkillsScore { get; set; }
    [Required]
    [Display(Name = "Total Score")]
    [Range(0, 100)]
    public int TotalScore { get; set; }
    [Required]
    public bool Modified { get; set; }
    [Required]
    [Display(Name = "Modified By")]
    public int ModifiedById { get; set; }
    [Required]
    [Display(Name = "Modified On")]
    public DateTime? ModifiedOn { get; set; }
    public bool Completed { get; set; }
    [Required]
    [Display(Name = "Completed By")]
    public int CompletedById { get; set; }
    [Required]
    [Display(Name = "Completed On")]
    public DateTime? CompletedOn { get; set; }
    public bool Published { get; set; }
    [Required]
    [Display(Name = "Published By")]
    public int PublishedById { get; set; }
    [Required]
    [Display(Name = "Published On")]
    public DateTime? PublishedOn { get; set; }
    [Required]
    [Display(Name = "Template")]
    public int TemplateId { get; set; }

和UserProfile:

 public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string DisplayName { get; set; }

提前致谢。

1 个答案:

答案 0 :(得分:1)

请查看以下链接Relationships in EF5 - Code First。这可能就是你要找的东西。

如果您遇到问题,也可以参考this

最后在这个ASP Forum中,还有更多信息