实体框架RC1 - MetadataItem.Annotations内部 - 替代?

时间:2013-08-22 10:10:51

标签: c# entity-framework entity-framework-6

我一直在EF Beta1中使用以下方法来获取引用给定类型的PropertyInfos列表:

public static List<PropertyInfo> GetReferencingAssociations(Type entityType, ObjectContext objectContext)
        {
            var result = (from edmType in objectContext.MetadataWorkspace.GetItems<EntityType>(DataSpace.CSpace)
                          from navigationProperty in edmType.NavigationProperties
                          let propertyInfo = (PropertyInfo)navigationProperty.Annotations.Single(y => y.Name == "ClrPropertyInfo").Value
                          where propertyInfo.PropertyType == entityType
                          select propertyInfo).ToList();

            return result;
        }

然而,在最近发布的RC1(see)中,System.Data.Entity.Core.Metadata.Edm.MetadataItem的注释 - 属性已经内部化了。

我的快速解决方法是使用反射来访问内部属性,但我想知道是否有任何其他解决方案来获取给定NavigationProperty的PropertyInfo而没有反射黑客。

1 个答案:

答案 0 :(得分:0)

注释由MetadataProperty实例在内部表示。您应该能够从MetadataItem.MetadataProperties集合中检索注释。可以使用MetadataItem.AddAnnotationMetadataItem.RemoveAnnotation添加/删除注释。

相关问题