• 09-10-2021, 20:06:29
    #1
    Merhabalar oluşturduğum projede migration oluştururken hatayla karşılaşıyorum


    ilk tabloda
    public int CreatedUserId { get; set; }
    public User CreatedUser { get; set; }
    public int ModifiedUserId { get; set; }
    public User ModifiedUser { get; set; }

    user tablosunda da
    public ICollection<Advert> CreatedAdverts { get; set; }
    public ICollection<Advert> ModifiedAdverts { get; set; }

    bu şekilde ilişkilendiriyorum

    builder.HasOne<User>(a => a.CreatedUser).WithMany(c => c.CreatedAdverts).HasForeignKey(x => x.CreatedUserId);
    builder.HasOne<User>(a => a.ModifiedUser).WithMany(c => c.ModifiedAdverts).HasForeignKey(x => x.ModifiedUserId);

    ilişkilendirirken de bu şekilde yapıyorum ancak migration oluştururken bu hatayı alıyorum
    Unable to determine the relationship represented by navigation 'Advert.CreatedUser' of type 'User'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

    sizce nerede hata yapıyorum yardımcı olabilir misiniz ?
  • 09-10-2021, 20:21:32
    #2
    Buradaki cevap işinizi görür hocam. Fikir verebilir.
  • 22-11-2021, 20:06:29
    #3
    İki sütunuda User tablosu ile ilşkilendirdiğiniz için hata alıyorsunuz.Mapping etmede hata verir. Ayrı bir tabloda Modified useri illa ilişkilendirebilir yada benim şuan yaptığım gibi Id ile barındırabilirsiniz.

    public int CreatedUserId { get; set; }
    public virtual User CreatedUser { get; set; }
    public int ModifiedUserId { get; set; }


    user tablosunda da
    public ICollection<Advert> CreatedAdverts { get; set; }