【发布时间】:2016-02-02 14:08:52
【问题描述】:
我有一个具有一些属性和行为的基类。这个基类被许多其他类扩展/继承。其中一些类应该在它们自己的属性之一和基类的一个属性上创建唯一的多列索引。
public class BaseClass
{
long employeeId {get; set;}
// and many other things...
}
public class Buzzword : BaseClass
{
string Name {get;set;} // supposed to be unique for every employee
// many other things...
}
我现在想要的是这样的,重复我的 Buzzword 课程:
public class Buzzword : BaseClass
{
[Index("IX_Buzzword_EmployeeId_Name", IsUnique = true, Order = 1]
// black magic: inherited property of BaseClass
[Index("IX_Buzzword_EmployeeId_Name", IsUnique = true, Order = 2]
string Name {get;set;} // supposed to be unique for every employee
// many other things...
}
我该怎么做?将employeeId 设为虚拟(因此仍在所有子类中实现)并在类中覆盖它以进行多列索引定义(以及对基本实现的调用)?
亲切的问候, 伴侣
【问题讨论】:
-
请阅读此内容并考虑修改您的标题以删除标签:meta.stackexchange.com/questions/19190/…
标签: c# entity-framework inheritance multiple-columns code-first