Esempio n. 1
0
        private static void DoLoadCollection <T, TProperty>(DbContext context, EntityEntry <T> entry, FilteredIncludeExpression filteredInclude) where T : class where TProperty : class
        {
            List <TProperty> collection = filteredInclude.Filter != null
                ? entry.Collection((Expression <Func <T, IEnumerable <TProperty> > >) filteredInclude.Include)
                                          .Query()
                                          .Where((Expression <Func <TProperty, bool> >)filteredInclude.Filter).ToList()
                : entry.Collection((Expression <Func <T, IEnumerable <TProperty> > >)filteredInclude.Include)
                                          .Query()
                                          .ToList();

            if (filteredInclude.FilteredIncludes == null || filteredInclude.FilteredIncludes.Count == 0)
            {
                return;
            }

            filteredInclude.FilteredIncludes.ToList().ForEach(exp =>
            {
                context.InvokeMethodForCollection
                (
                    collection,
                    exp.Include.Body.GetMemberExpression().GetMemberType(),
                    exp
                );
            });
        }
Esempio n. 2
0
 private static void InvokeMethodForCollection <T>(this DbContext context, List <T> list, Type memberType, FilteredIncludeExpression filteredIncludes) where T : class
 {
     if (memberType.IsList())
     {
         list.ForEach(item =>
         {
             LOAD_COLLECTION_METHOD.GetMethod().MakeGenericMethod
             (
                 typeof(T),
                 memberType.GetUnderlyingElementType()
             ).Invoke(null, new object[] { context, context.GetEntry(item), filteredIncludes });
         });
     }
     else
     {
         list.ForEach(item =>
         {
             LOAD_REFERENCE_METHOD.GetMethod().MakeGenericMethod
             (
                 typeof(T),
                 memberType
             ).Invoke(null, new object[] { context, context.GetEntry(item), filteredIncludes });
         });
     }
 }
Esempio n. 3
0
        private static void InvokeMethodForReference <T>(this DbContext context, T property, Type memberType, FilteredIncludeExpression filteredIncludes) where T : class
        {
            if (property == null)
            {
                return;
            }

            if (memberType.IsList())
            {
                LOAD_COLLECTION_METHOD.GetMethod().MakeGenericMethod
                (
                    typeof(T),
                    memberType.GetUnderlyingElementType()
                ).Invoke(null, new object[] { context, context.GetEntry(property), filteredIncludes });
            }
            else
            {
                LOAD_REFERENCE_METHOD.GetMethod().MakeGenericMethod
                (
                    typeof(T),
                    memberType
                ).Invoke(null, new object[] { context, context.GetEntry(property), filteredIncludes });
            }
        }
Esempio n. 4
0
        private static void DoLoadReference <T, TProperty>(DbContext context, EntityEntry <T> entry, FilteredIncludeExpression filteredInclude) where T : class where TProperty : class
        {
            TProperty property = entry.Reference((Expression <Func <T, TProperty> >)filteredInclude.Include)
                                 .Query()
                                 .SingleOrDefault((Expression <Func <TProperty, bool> >)filteredInclude.Filter);

            if (filteredInclude.FilteredIncludes == null || filteredInclude.FilteredIncludes.Count == 0)
            {
                return;
            }

            filteredInclude.FilteredIncludes.ToList().ForEach(exp =>
            {
                context.InvokeMethodForReference <TProperty>
                (
                    property,
                    exp.Include.Body.GetMemberExpression().GetMemberType(),
                    exp
                );
            });
        }