Cannot get relationship to update for navigation properties in entity framework

后端 未结 3 652
梦谈多话
梦谈多话 2020-12-05 21:38

I am currently using EF4.3 and Code First. Creation of my objects works (via my views - just using the auto-generated Create), but when I attempt to edit an object, it does

3条回答
  •  佛祖请我去吃肉
    2020-12-05 22:24

    I am not sure exactly what you mean by navigation properties? Do you mean like a foreign key relationship? If so then try the following data annotation:

    public class Project
    {
        public int ProjectID { get; set; }
    
        [Required]
        public string Name { get; set; }
    
        [ForeignKey("YourNavigationProperty")]
        public virtual UserManager { get; set; }
    }
    

    Update your EF Context, and see what happens?

    UPDATE

    public class Project
    {
        public int ProjectID { get; set; }
    
        [Required]
        public string Name { get; set; }
    
        [ForeignKey("ManagerId")]
        public ManagerModel UserManager { get; set; }
    }
    
    public class ManagerModel
    {
        [Key]
        public int ManagerId { get; set; }
    
        public String ManagerName { get; set; }
    }
    

    See if that works?

提交回复
热议问题