Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration results in "Sequence contains no elements" error

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...

like image 820
Colin Avatar asked Apr 20 '15 10:04

Colin


1 Answers

There was also a database computed field in the Block class. Removing that (as well as self referencing properties) let me run a migration.

like image 85
Colin Avatar answered Oct 25 '22 04:10

Colin