Entityframework RC1-MetadataItem.注释为内部-备选项
本文关键字:选项 内部 RC1-MetadataItem 注释 Entityframework | 更新日期: 2023-09-27 18:28:40
我在EF Beta1中使用了以下方法来获取PropertyInfos列表,这些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(请参阅)中,Annotations-System.Data.Entity.Core.Metadata.Edm.MetadataItem的属性已设置为内部。
我的快速解决方法是使用反射来访问内部属性,但我想知道是否有其他解决方案可以在不使用反射破解的情况下获得给定NavigationProperty的PropertyInfo。
注释在内部由MetadataProperty
实例表示。您应该能够从MetadataItem.MetadataProperties
集合中检索注释。可以分别使用MetadataItem.AddAnnotation
和MetadataItem.RemoveAnnotation
来添加/移除注释。