2013-08-22 31 views
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反射黑客。

回答

0

的註釋由MetadataProperty實例內部表示。您應該能夠從MetadataItem.MetadataProperties集合中檢索註釋。註釋可以被添加/使用MetadataItem.AddAnnotation和分別MetadataItem.RemoveAnnotation除去。