【问题标题】:Entityframework RC1 - MetadataItem.Annotations made internal - alternatives?Entityframework RC1 - MetadataItem.Annotations 内部 - 替代品?
【发布时间】:2013-08-22 10:10:50
【问题描述】:

我一直在 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) 中,Annotations-System.Data.Entity.Core.Metadata.Edm.MetadataItem 的属性已被设置为内部属性。

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2022-09-28
      • 2011-05-16
      • 1970-01-01
      • 2011-10-21
      • 2018-01-24
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多