Here we are on EF Core and got 3 tables:
And more (except News, Items): Content, Post, Form, etc.
And my model definitions
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public Link Link { get; set; }
}
public class News
{
public int Id { get; set; }
public string Header { get; set; }
public string Content { get; set; }
public Link Link { get; set; }
}
public class Link
{
public int Id { get; set; }
public string Type { get; set; }
public int RowId { get; set; }
public string Url { get; set; }
}
Table Links
describe URL for every News and every Item.
This means that Links
has 4 columns:
How to setup the relationships? Keep in mind that we need to resolve Entity by URL in Links table.
In order to have the property NewRow, and the constraints to the other two tables, you cold implement it like this:
public int RowId {
public get {
return this.Type.equals("news") ? NewsId.Value : ItemId.Value;
};
private set {
if(this.Type.equals("news")){
NewsId = value;
}
else{
ItemId = value;
}
}
}
And then set this property as not mapped on the ContextDB.