Entity Framework class instantiation behavior

前端 未结 1 337
滥情空心
滥情空心 2021-01-27 14:52

I am facing a problem where my entity framework keeps behaving weirdly when I try to instantiate any class. I am trying to use the default usermanager behaviour

相关标签:
1条回答
  • 2021-01-27 15:25

    You don't have any foreign key to link AssociatedUser. Try adding a property to link Notification to ApplicationUser using foreign key. Like

    public class Notification
    {
        //rest of properties
    
        //change int to whatever type your primary key is in 
        //ApplicationUser class. I have Guid for example.
        public int ApplicationUser AssociatedUserId {get;set;}
    }
    

    Then try modifying configuration like this:

       modelBuilder.Entity<Notification>()
            .HasRequired(c => c.AssociatedUser)
            .WithMany(c => c.Notifications)
            .HasForeignKey(n=>n.AssociatedUserId);
    
    0 讨论(0)
提交回复
热议问题