anonymous type creation linq.
This commit is contained in:
		
							parent
							
								
									7278dea56d
								
							
						
					
					
						commit
						515d0bee37
					
				| @ -77,7 +77,7 @@ namespace PoweredSoft.DynamicLinq.Helpers | ||||
|             return ret;             | ||||
|         } | ||||
| 
 | ||||
|         internal static IQueryable GroupBy(IQueryable query, Type type, List<(string path, string propertyName)> parts) | ||||
|         public static IQueryable GroupBy(IQueryable query, Type type, List<(string path, string propertyName)> parts) | ||||
|         { | ||||
|             // EXPRESSION | ||||
|             var parameter = Expression.Parameter(type, "t"); | ||||
| @ -95,6 +95,10 @@ namespace PoweredSoft.DynamicLinq.Helpers | ||||
| 
 | ||||
|             var anonymousType = TypeHelpers.CreateSimpleAnonymousType(fields); | ||||
| 
 | ||||
|             var constructorTypes = fields.Select(t => t.type).ToArray(); | ||||
|             var constructor = anonymousType.GetConstructor(constructorTypes); | ||||
|             var newExpression = Expression.New(constructor, partExpressions); | ||||
|             var genericMethod = Constants.GroupByMethod.MakeGenericMethod(type, anonymousType); | ||||
| 
 | ||||
|             return query; | ||||
|         } | ||||
|  | ||||
| @ -35,6 +35,12 @@ namespace PoweredSoft.DynamicLinq.Helpers | ||||
|             return ret; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Use this to create anonymous type concstructor for LINQ queries :) | ||||
|         /// https://stackoverflow.com/questions/6879279/using-typebuilder-to-create-a-pass-through-constructor-for-the-base-class | ||||
|         /// </summary> | ||||
|         /// <param name="fields"></param> | ||||
|         /// <returns></returns> | ||||
|         internal static TypeInfo CreateSimpleAnonymousType(List<(Type type, string name)> fields) | ||||
|         { | ||||
|             // DYNAMIC TYPE CREATION | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user