2
我一直使用EF Beta1的下列方法來獲取PropertyInfos,這是引用給定類型的列表:在最近發佈的RC1的EntityFramework RC1 - MetadataItem.Annotations做內部 - 選擇嗎?
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;
}
但是(see)的註釋系統,物業.Data.Entity.Core.Metadata.Edm.MetadataItem已在內部完成。
我快速的解決方法是使用反射來訪問內部屬性,但我不知道是否有任何其他的解決方案,得到了給定NavigationProperty的沒有的PropertyInfo反射黑客。