Unable to determine a valid ordering for dependent operations

entity-framework

Question

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.

1
24
11/2/2015 6:45:34 PM

Popular Answer

Another possible cause of this is if the foreign key property is set incorrectly.

For example, this can happen in the following scenario:

  1. DepartmentId is set to zero or any other value that isn't a valid foreign key.
  2. Department is either null or it is a Department object that contains a null value for its own DepartmentId property.
  3. This configuration will cause Entity Framework to fail because it tries to find a Department that has a primary key of zero, which probably won't exist.

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.

11
12/10/2014 4:29:31 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow