c# - Entityframework RC1 - MetadataItem.Annotations made internal - 替代方案?

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

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

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 的 Annotations-Property 已成为内部属性。

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

最佳答案

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

关于c# - Entityframework RC1 - MetadataItem.Annotations made internal - 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18377530/

相关文章:

c# - ExecuteStoreCommand 上出现奇怪的 EF6 性能问题

c# - 为什么 Microsoft Speech Recognition Semantic Value.Confidence 值始终为 1?

c# - 如何解决 Exception :Call was rejected by callee. (Exception from HRESULT : 0x80010001 (RPC_E_CALL_REJECTED)) in C#?

c# - 如何在 gridView 中显示某行的上下文菜单

c# - 使用属性读取 XML 的最简单方法

c# - ReferentialConstraint 中的依赖属性映射到存储生成的列。列 : 'ID'

asp.net-mvc - MVC 通过包含父值和子列表的 View 模型传递 View 模型 View

c# - 获取可在其具体类型中类型转换的相关实体

c# - 无法使用 Effort 框架在单元测试中使用现有数据库

entity-framework-6 - 属性表达式无效。表达式应该代表一个属性