These are my models:
public class Application
{
public Guid ID { get; set; }
public virtual Project MainProject { get; set; }
public virtual ICollection<Solution> Solutions { get; set; }
}
public class Solution
{
public Guid Id { get; set; }
public virtual Application Application { get; set; }
public virtual ICollection<Project> Projects { get; set; }
}
public class Project
{
public Guid Id { get; set; }
public virtual ICollection<Solution> Solutions { get; set; }
}
So basically, an Application has a list of Solutions, and a Solution has a list of Projects. An Application also has a Main Project (which will be somewhere in the group of Projects that is accessible through the Application's Solutions, but that's not forced by the DB).
I've got an issue when I try to add a new Application that has the MainProject property set.
Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.
I don't understand what the problem is. MainProject is not mandatory, in fact the insert works if I don't set that property. There is a circular dependency, but there is a clear order that works
- Insert application with no main project
- Insert solutions
- Insert projects
- Update application to set relevant project as main project.
Is there any way to tell Entity Framework to do this?
edit:
Here are the configurations:
public ApplicationConfiguration()
: base()
{
HasKey(a => a.ID);
ToTable("Applications");
HasOptional(a => a.MainProject);
}
public SolutionConfiguration()
: base()
{
ToTable("Solutions");
}
public ProjectConfiguration()
: base()
{
ToTable("Projects");
}