This is my model
public string Content { get; set; }
public Faq Reply { set; get; }
public int? ReplyId { get; set; }
public ICollection<Faq> Children { get; set; }
[ForeignKey("WriterId")]
public virtual UserProfile Writer { get; set; }
public virtual int? WriterId { get; set; }
public Status Status { get; set; }
[ForeignKey("DepartmentId")]
public virtual Department Department { get; set; }
public virtual int? DepartmentId { get; set; }
And this is my error
Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.
Another possible cause of this is if the foreign key property is set incorrectly.
For example, this can happen in the following scenario:
I ran into this exception once when I mapped one object to another and I incorrectly set the foreign key to zero instead of setting it to null.
I can't say that this configuration is what is causing your exception without seeing the actual values of the properties, but it is one possibility.