【发布时间】:2015-02-20 15:41:48
【问题描述】:
我正在使用 Entity Framework Power Tools 来生成数据库模型类。 它使用 HasKey() 方法来定义类的 Key Attribute。 在我的应用程序代码中使用它时,有什么方法可以找到我的类的关键属性? 有什么方法可以检查特定属性是否为关键属性?
public class MyTableMap : EntityTypeConfiguration<MyTable>
{
public MyTableMap()
{
// Primary Key
this.HasKey(t => t.RecordID);
}
}
我正在尝试使用以下方法查找关键属性,但它不起作用
if (propertyInfoObj.GetCustomAttributes(false).Any(x => x.GetType() == typeof(KeyAttribute)))
【问题讨论】:
-
“但它不工作” - 错误信息?
标签: c# entity-framework attributes key