Include all navigation properties using Reflection in generic repository using EF Core

后端 未结 2 926
滥情空心
滥情空心 2020-12-03 06:06

I\'m working on creating a generic repository for an EF Core project to avoid having to write CRUD for all models. A major roadblock I\'ve hit is navigation properties not b

2条回答
  •  余生分开走
    2020-12-03 06:47

        private List GetNavigationProperties(GesFormaContext _gesFormaContext)
        {
            List propertyInfos = new List();
            _gesFormaContext.Model.GetEntityTypes().Select(x => x.GetNavigations()).ToList().ForEach(entityTypes =>
            {
                entityTypes.ToList().ForEach(property =>
                {
                    propertyInfos.AddRange(typeof(T).GetProperties().Where(x => x.PropertyType == property.PropertyInfo.PropertyType).ToList());
                });
    
            });
    
    
            return propertyInfos;
        }
    

提交回复
热议问题