【发布时间】:2023-03-17 22:50:01
【问题描述】:
在 EF6 中,此方法用于检索实体的导航属性:
private List<PropertyInfo> GetNavigationProperties<T>(DbContext context) where T : class
{
var entityType = typeof(T);
var elementType = ((IObjectContextAdapter)context).ObjectContext.CreateObjectSet<T>().EntitySet.ElementType;
return elementType.NavigationProperties.Select(property => entityType.GetProperty(property.Name)).ToList();
}
IObjectContextAdapter 但是在 EF Core 中不存在。我应该从哪里获取实体的导航属性列表?
【问题讨论】: