Guest User

Guest User

  • Tech Writer
  • 98
  • 40.1k

One (1) table with 3 Foreign Keys - Need to Reference

Jan 20 2020 11:43 PM
This is my tables in SQL Server with Category table and need to be reference in Product table with 3 CategoryId.
What solution should I do? especially in Entity Core..
Do I need to 2 more tables for Category with the same content?
 
what I did to the entity is just like the code below but I'm not sure if this is correct or not..
 
public class Category
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public class Product
{
public Guid Id { get; set; }
public Guid CategoryId2 { get; set; }
public Guid CategoryId3 { get; set; }
public string Code { get; set; }
public string Name { get; set; }
[ForeignKey("Category")]
public Guid CategoryId1 { get; set; }
public virtual Category Category { get; set; }

Answers (1)