Pregunta

I have a UserProfile with a UserId. I need to create a relationship to a table Scorecards where there are multiple columns that need to have a relationship with UserId. They are ScorerId, CreatedById, AgentId, ModifiedById, PublishedById ....

I am unsure of how this would be done via code first approach with mvc 4 and entity 5?

Any Help would be appreciated.

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; }

And 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; }

Thanks in advance.

¿Fue útil?

Solución

Look at the following link Relationships in EF5 - Code First. It might be what you are looking for.

You can also refer to this if you get stuck.

And lastly in this ASP Forum, is some more information

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top