1
我有以下的类/实体:实体框架重复列
public class Product : ISaleable
{
public void ProcessSale()
{
return;
}
[NotMapped]
private int id { get; set; }
[NotMapped]
private string productName { get; set; }
[NotMapped]
private decimal price { get; set; }
[NotMapped]
private TaxClass taxClass { get; set; }
[NotMapped]
private int quantity { get; set; }
[NotMapped]
private Member memberAssociation { get; set; }
public TaxClass TaxClass
{
get
{
return this.taxClass;
}
set
{
this.taxClass = value;
}
}
public int Quantity
{
get
{
return this.quantity;
}
set
{
this.quantity = value;
}
}
public string ProductName
{
get
{
return this.productName;
}
set
{
this.productName = value;
}
}
public decimal Price
{
get
{
return this.price;
}
set
{
this.price = value;
}
}
public Member MemberAssociation
{
get
{
return this.memberAssociation;
}
set
{
this.memberAssociation = value;
}
}
[Key]
public int ID
{
get
{
return this.id;
}
set
{
this.id = value;
}
}
}
正如你所看到的,这个类从ISaleable继承和有型TaxClass的两个元素。现在,当项目运行时,EF试图为此实体创建表时,我会得到以下例外:
每个表中的列名必须是唯一的。表'Product'中的列名称'TaxClass_ID' 指定了多次。
我不知道为什么会发生这种情况,任何帮助表示赞赏。
这工作!我也必须重新命名'Public MemberAssocation'。谢谢! – gunwin 2012-01-14 19:07:41
没问题!我应该指出,你首先得到错误的原因是关系(可能)尚未建立。因此EF不确定您的TaxClass与您的产品的关系。看看这里的文章了解更多信息:http://elegantcode.com/2009/12/15/entity-framework-poco-ef4-a-simple-mapping/ – Nick 2012-01-14 19:22:30
我改变了列的名称与财产(f => f.Id).HasColumnName(“MyNewID”); 不确定这是否适用于您。这个设置被称为Fluent API btw。 – jonas 2013-02-19 12:43:17