I want create a Product entity and that entity can have list of Products as LinkedProducts but I don't know why my codes not working. I'm student and very newbie to EF core mapping.
I created 2 Entity Classes Product.cs and ProductLink.cs, here is my classes
Product.cs
public class Product : Content
{
public virtual string Description { get; set; }
public virtual Guid? ThumbnailImageId { get; set; }
[ForeignKey("ThumbnailImageId")]
public virtual Media ThumbnailImage { get; set; }
public virtual List<ProductLink> ProductLinks { get; set; } = new List<ProductLink>();
}
ProductLink.cs
public class ProductLink : EntityBase
{
[ForeignKey("ProductId")]
public virtual Product Product { get; set; }
public virtual Guid? ProductId { get; set; }
[ForeignKey("LinkedProductId")]
public virtual Product LinkedProduct { get; set; }
public virtual Guid? LinkedProductId { get; set; }
}
Error :
Unable to determine the relationship represented by navigation property 'Product.ProductLinks' of type 'List'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.