实体框架,从MetadataWorkspace获取属性的ConcurrencyMode,如何实现?

时间:2012-01-31 17:10:14

标签: c# entity-framework-4

给定实体类型,如何通过内省CSpace的MetadataWorkspace在运行时发现该实体类型的属性的ConcurrencyMode? 谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用TypeUsage.Facets

[EntityContext] etContext = new [EntityContext]();
var csdl = etContext.MetadataWorkspace.GetItemCollection(DataSpace.CSpace);
var entity = csdl.GetItems<EntityType>().Where(e => e.Name = [EntityType]).SingleOrDefault();
var edmProperty = entity.Properties.Where(p => p.Name == [PropertyName]).SingleOrDefault();
var mode = edmProperty.TypeUsage.Facets.Where(f => f.Name ==     "ConcurrencyMode").SingleOrDefault();