我已经在至少 2 个地方(此处和此处)看到了用于读取实体框架 EdmProperty 的 StoreGeneratedPattern 属性(已计算、身份或无)的示例代码,但它不适用于我的模型。我的上下文是一个ObjectContext,版本是EF5;也许这段代码与 EF5 冲突?当我查看模型中此属性/列的属性时,它显示了身份。
这是我的代码:
using ( var context = new MyApplicationEntities() )
{
var entityType = ( (EntityConnection)context.Connection )
.GetMetadataWorkspace() // can't call context.MetadataWorkspace - storage model will not be present
.GetType( "MyEntityTypeWithIdentityColumn", "MyApplicationModel.Store", DataSpace.SSpace ) as EntityType;
EdmMember identityColumn = entityType.Members["MyIdentityColumn"];
Facet item;
// All I get here for Facets is Nullable & DefaultValue
if ( identityColumn.TypeUsage.Facets.TryGetValue( "StoreGeneratedPattern", false, out item ) )
{
var value = ( (StoreGeneratedPattern)item.Value ) == StoreGeneratedPattern.Identity;
}
}