/// <summary>Enumerates create enumerable in this collection.</summary> /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// <returns> /// An enumerator that allows foreach to be used to process create enumerable in this collection. /// </returns> public IEnumerable <T> CreateEnumerable() { if (Childs.Count == 0) { return(OriginalQueryable); } IQueryable newQuery = null; var createAnonymousFromQueryMethod = GetType().GetMethod("CreateAnonymousFromQuery"); foreach (var child in Childs) { var childQuery = child.CreateIncludeQuery(OriginalQueryable); if (newQuery == null) { newQuery = OriginalQueryable.Select(x => new { x, child = childQuery }); } else { // REFLECTION: newQuery.CreateAnonymousFromQuery<TElement>(newQuery, childQuery); var createAnonymousFromQueryMethodGeneric = createAnonymousFromQueryMethod.MakeGenericMethod(newQuery.ElementType); newQuery = (IQueryable)createAnonymousFromQueryMethodGeneric.Invoke(this, new object[] { newQuery, childQuery }); } } // REFLECTION: newQuery.ToList(); var toListMethod = typeof(Enumerable).GetMethod("ToList").MakeGenericMethod(newQuery.ElementType); var toList = (IEnumerable <object>)toListMethod.Invoke(null, new object[] { newQuery }); try { // TODO: Optimize this code while (true) { toList = toList.Select(x => ((dynamic)x).x).ToList(); if (!toList.Any()) { return(new List <T>()); } } } catch (Exception) { } var list = toList.Cast <T>().ToList(); #if EF6 // FIX lazy loading QueryIncludeFilterLazyLoading.SetLazyLoaded(list, Childs); #endif // FIX null collection QueryIncludeFilterNullCollection.NullCollectionToEmpty(list, Childs); return(list); }
/// <summary>Creates the queryable.</summary> /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// <returns>The new queryable.</returns> public IQueryable CreateQueryable() { if (Childs.Count == 0) { return(OriginalQueryable); } IQueryable newQuery = null; var createAnonymousFromQueryMethod = GetType().GetMethod("CreateAnonymousFromQuery"); foreach (var child in Childs) { var childQuery = child.CreateIncludeQuery(OriginalQueryable); if (newQuery == null) { newQuery = OriginalQueryable.Select(x => new { x, q = childQuery }); } else { // REFLECTION: newQuery.CreateAnonymousFromQuery<TElement>(newQuery, childQuery); var createAnonymousFromQueryMethodGeneric = createAnonymousFromQueryMethod.MakeGenericMethod(newQuery.ElementType); newQuery = (IQueryable)createAnonymousFromQueryMethodGeneric.Invoke(this, new object[] { newQuery, childQuery }); } } return(newQuery); }
/// <summary>Enumerates create enumerable in this collection.</summary> /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// <returns> /// An enumerator that allows foreach to be used to process create enumerable in this collection. /// </returns> public IEnumerable <T> CreateEnumerable() { if (Childs.Count == 0) { return(OriginalQueryable); } IQueryable newQuery = null; var createAnonymousFromQueryMethod = GetType().GetMethod("CreateAnonymousFromQuery"); foreach (var child in Childs) { var childQuery = child.CreateIncludeQuery(OriginalQueryable); if (newQuery == null) { newQuery = OriginalQueryable.Select(x => new { x, child = childQuery }); } else { // REFLECTION: newQuery.CreateAnonymousFromQuery<TElement>(newQuery, childQuery); var createAnonymousFromQueryMethodGeneric = createAnonymousFromQueryMethod.MakeGenericMethod(newQuery.ElementType); newQuery = (IQueryable)createAnonymousFromQueryMethodGeneric.Invoke(this, new object[] { newQuery, childQuery }); } } // REFLECTION: newQuery.ToList(); var toListMethod = typeof(Enumerable).GetMethod("ToList").MakeGenericMethod(newQuery.ElementType); var toList = (IEnumerable <object>)toListMethod.Invoke(null, new object[] { newQuery }); try { // TODO: Optimize this code while (true) { toList = toList.Select(x => ((dynamic)x).x).ToList(); } } catch (Exception) { } return(toList.Cast <T>()); }
/// <summary>Enumerates create enumerable in this collection.</summary> /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// <returns> /// An enumerator that allows foreach to be used to process create enumerable in this collection. /// </returns> public IEnumerable <T> CreateEnumerable() { IEnumerable <T> newEnumerable; switch (Queries.Count) { case 1: { var p0 = Queries[0].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0 }).ToList().Select(x => x.x); break; } case 2: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1 }).ToList().Select(x => x.x); break; } case 3: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2 }).ToList().Select(x => x.x); break; } case 4: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); var p3 = Queries[3].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2, p3 }).ToList().Select(x => x.x); break; } case 5: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); var p3 = Queries[3].Select(OriginalQueryable); var p4 = Queries[4].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2, p3, p4 }).ToList().Select(x => x.x); break; } case 6: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); var p3 = Queries[3].Select(OriginalQueryable); var p4 = Queries[4].Select(OriginalQueryable); var p5 = Queries[5].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2, p3, p4, p5 }).ToList().Select(x => x.x); break; } case 7: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); var p3 = Queries[3].Select(OriginalQueryable); var p4 = Queries[4].Select(OriginalQueryable); var p5 = Queries[5].Select(OriginalQueryable); var p6 = Queries[6].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2, p3, p4, p5, p6 }).ToList().Select(x => x.x); break; } case 8: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); var p3 = Queries[3].Select(OriginalQueryable); var p4 = Queries[4].Select(OriginalQueryable); var p5 = Queries[5].Select(OriginalQueryable); var p6 = Queries[6].Select(OriginalQueryable); var p7 = Queries[7].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2, p3, p4, p5, p6, p7 }).ToList().Select(x => x.x); break; } case 9: { var p0 = Queries[0].Select(OriginalQueryable); var p1 = Queries[1].Select(OriginalQueryable); var p2 = Queries[2].Select(OriginalQueryable); var p3 = Queries[3].Select(OriginalQueryable); var p4 = Queries[4].Select(OriginalQueryable); var p5 = Queries[5].Select(OriginalQueryable); var p6 = Queries[6].Select(OriginalQueryable); var p7 = Queries[7].Select(OriginalQueryable); var p8 = Queries[8].Select(OriginalQueryable); newEnumerable = OriginalQueryable.Select(x => new { x, p0, p1, p2, p3, p4, p5, p6, p7, p8 }).ToList().Select(x => x.x); break; } default: { throw new Exception(ExceptionMessage.QueryIncludeQuery_ToManyInclude); } } return(newEnumerable); }