I created a model with 3 classes using table-per-hierarchy inheritance, and with 2 foreign keys that self reference the hierarchy table.
I have a BaseProperty
class with a self referencing key CloneID
and navigation property Clone
:
public class BaseProperty
{
public int ID {get; set; }
public int? CloneID {get; set; }
public BaseProperty Clone {get; set; }
//If I add this code, when I use Add-Migration -
//Sequence contains no elements error
//public int? TriggeredCloneID {get; set;}
}
I have a Property
class that inherits BaseProperty
and has a foreign key BlockID
and a Block
navigation property.
public class Property : BaseProperty
{
public int? BlockID { get; set; }
public Block { get; set; }
}
I have a Block
class that inherits BaseProperty
and has a Properties
navigation property:
public class Block: BaseProperty
{
public ICollection<Property> Properties { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public int? ComputedNumberOfProperties { get; set; }
}
Note that the Block
property in the Property
class is also self referencing because both Property
and Block
inherit BaseProperty
and I am using table-per-hierarchy inheritance.
It has been working and is in a production system with live data. Now I want to add a field (just a standard int?
property) to the base class and I get a "Sequence contains no elements" error when I add a migration.
I found the open issue at https://entityframework.codeplex.com/workitem/569, so I tried the workaround described and removed the self-referencing keys and navigation properties, but that migration failed with the same error. I now appear to be completely skewered...
There was also a database computed field in the Block class. Removing that (as well as self referencing properties) let me run a migration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With