EF5 How to get list of navigation properties for a domain object

后端 未结 4 716
一整个雨季
一整个雨季 2020-12-06 14:09

I\'m working on an EF 5 Code-First solution and I am trying to update an existing entity with a modified one using the Repository pattern:

    public void Up         


        
4条回答
  •  青春惊慌失措
    2020-12-06 15:01

    Based on Zev's answer:

    public List GetNavigationProperties(DbContext context) where T : class
    {
        var entityType = typeof(T);
        var elementType = ((IObjectContextAdapter)context).ObjectContext.CreateObjectSet().EntitySet.ElementType;
        return elementType.NavigationProperties.Select(property => entityType.GetProperty(property.Name)).ToList();
    }
    

提交回复
热议问题