I have a Template class
public class Template
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Category> Categories { get; set; }
public virtual Template RelatedTemplate { get; set; }
public virtual Field RelatedTemplatePrimaryField { get; set; }
public virtual ICollection<Field> Fields { get; set; }
}
And a Field class
public class Field
{
public int Id { get; set; }
public string Name { get; set; }
public int Min { get; set; }
public int Max { get; set; }
public bool AllowEmpty { get; set; }
public bool IsCollection { get; set; }
public virtual ICollection<Template> Templates { get; set; }
}
The problem is it’s not creating a many to many relationship, it just adds a FK on the fields table, I want a many to many relationship on
Fields ICollection<Field> Fields
and
ICollection<Template> Templates
EDIT:
If I remove
public virtual Template RelatedTemplate { get; set; }
public virtual Field RelatedTemplatePrimaryField { get; set; }
It works… Any ideas?
This is a case where you must help EF to correctly recognize your relations. You can do it either by data annotations:
or by fluent-API: