迁移导致“序列不含元素”错误 [英] Migration results in "Sequence contains no elements" error

查看:71
本文介绍了迁移导致“序列不含元素”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有3个类的模型,它使用了每个层次的继承,并且使用了两个自引用层次结构表的外键。

I created a model with 3 classes using table-per-hierarchy inheritance, and with 2 foreign keys that self reference the hierarchy table.

我有一个 BaseProperty 具有自引用键的类 CloneID 和导航属性克隆

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;}
}

我有一个属性 c继承 BaseProperty 并具有外键 BlockID 导航属性。

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; }
}

我有一个阻止继承 BaseProperty 并具有属性导航属性的类:

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; }
}

请注意,阻止 Property 类中的c>属性也是自引用的,因为 Property Block inherit BaseProperty ,我使用每层次继承继承。

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.

它一直在工作并且在具有实时数据的生产系统中。现在我想添加一个字段(只是一个标准的 int?属性)到基类,当我添加一个迁移时,我得到一个序列不包含元素错误。

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.

我在 https://entityframework.codeplex.com上发现了未解决的问题/ workitem / 569 ,所以
我尝试了描述的解决方法,并删除了自引用键和导航属性,但是迁移失败,出现相同的错误。我现在看起来完全是串的...

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

推荐答案

Block类中还有一个数据库计算字段。删除它(以及自引用属性)让我运行迁移。

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

这篇关于迁移导致“序列不含元素”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆