我的所有实体都有一个基类:
public class Entity<TKey> : IEntity<TKey>
{
dynamic IEntity.Id
{
get
{
return this.Id;
}
set
{
this.Id = value;
}
}
public TKey Id { get; set; }
}
例如状态实体:
[MetadataType(typeof(StatusMetadata))]
public partial class Status : Entity<byte>
{
public string Title { get; set; }
}
当我对数据库运行查询时,出现以下错误:“元数据集合中已存在标识为“Id”的项目。参数名称:项目”。
有什么方法可以解决这个问题,或者这是由继承引起的问题,我无法从任何类继承我的实体?
这似乎是一个一般性错误,在寻找一些见解时,我看到:
Two tables can have the same name for a primary key. Look at the LightSwitch tables, they all have a primary key called Id.
At http://social.msdn.microsoft.com/Forums/vstudio/en-US/bd8d47da-d1b4-4be8-a7e5-193fb5360060/the-item-with-identity-actionpk-already-exists-in-the-metadata-收藏?论坛=lightswitch http://social.msdn.microsoft.com/Forums/vstudio/en-US/bd8d47da-d1b4-4be8-a7e5-193fb5360060/the-item-with-identity-actionpk-already-exists-in-the-metadata-collection?forum=lightswitch
因此,我检查了所有实体,并得到了一个 Identiy 数据类型已更改的实体,并继承了另一个具有 int Id 属性的类。
我要改变这个吗public new string Id { get; set; }
to public string Id { get; set; }
像其他人一样并删除继承,一切正常。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)