Wednesday, 7 August 2013

EF5: Can't Get StoreGeneratedPattern Property From Model

EF5: Can't Get StoreGeneratedPattern Property From Model

I've seen sample code for reading an EF EdmProperty's
StoreGeneratedPattern property (computed, identity, or none) in at least 2
places (here & here), but it doesn't work with my model. My context is an
ObjectContext, the version is EF5; maybe this code broke with EF5? When I
look at the properties for this property/column in the model, it shows
identity.
Here is my code:
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.Computed;
}
}

No comments:

Post a Comment