代码优先:“序列包含多个匹配元素”生成模式时的异常 [英] Code First: "Sequence contains more than one matching element" Exception when generating schema

查看:89
本文介绍了代码优先:“序列包含多个匹配元素”生成模式时的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的模型:

 


public Class Item {

  public int Id { get; set;}
  public int Name { get; set; }

  public virtual Item ParentItem { get; set; }
  public virtual ICollection<Item> ChildrenItems { get; set; }
}
<br/>

推荐答案

嗨肯,

不幸的是,这看起来像一个用于自引用IAs的映射配置的错误。

Unfortunately this looks like a bug with mapping configuration for self-referencing IAs.

一种解决方法是通过添加FK属性"ParentItemId"来创建关联作为FK关联。到你的Item类。如果这样做,您将不需要任何显式的关联配置,因为ParentItemId将被自动检测为
FK。

One workaround is to create the association as an FK association by adding the FK property "ParentItemId" to your Item class. If you do that you won't need any explicit configuration of the association as ParentItemId will be automatically detected as the FK.

我们将在下一个版本中修复该错误。

We will fix the bug in the next release.

干杯,

Andrew。

 


这篇关于代码优先:“序列包含多个匹配元素”生成模式时的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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