Defining many to many relation in code first entity framework

前端 未结 3 480
孤独总比滥情好
孤独总比滥情好 2021-02-06 13:45

I have 3 classes in my model as you can see below.

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseG         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 13:56

    Try doing it like this:

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
    
        public string UserName { get; set; }
    
        [InverseProperty("UserProfiles")]
        public IList MartialArts { get; set; }
    }
    
    [Table("MartialArt")]
    public class MartialArt
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
    
        public string Name { get; set; }
    
        public string Description { get; set; }
    
        public string IconPath { get; set; }
    
        public string ImagePath { get; set; }
    
        [InverseProperty("MartialArts")]
        public IList UserProfiles { get; set; }
    }
    

提交回复
热议问题