private Expression CreateCrossJoin( Expression first, LambdaExpression collectionSelector, string firstName, string secondName) { Type firstType = TypeHelper.GetElementType(first.Type); Type secondType = TypeHelper.GetElementType(collectionSelector.Body.Type); Dictionary <string, Type> resultTypeProps = new Dictionary <string, Type> { { firstName, firstType }, { secondName, secondType } }; // Create result selector Type resultType = DataRowFactory.Create(resultTypeProps); IKeyInfoHelper helper = new DataRowKeyInfoHelper(resultType); ParameterExpression firstParam = Expression.Parameter(firstType); ParameterExpression secondParam = Expression.Parameter(secondType); LambdaExpression resultSelector = Expression.Lambda( helper.CreateKeyFactoryExpression(firstParam, secondParam), firstParam, secondParam); return(queryMethodExpressionBuilder.SelectMany( first, collectionSelector, resultSelector)); }
public void DataRow_same_definition_should_result_in_same_type() { IDictionary <string, Type> definition = CreateRichDefinition(); Type datarow1 = DataRowFactory.Create(definition); Type datarow2 = DataRowFactory.Create(definition); datarow1.Should().BeSameAs(datarow2); }
private static Type CreateType(params string[] names) { Dictionary <string, Type> props = new Dictionary <string, Type>(); for (int i = 0; i < names.Length; i++) { props.Add(names[i], typeof(int)); } return(DataRowFactory.Create(props)); }
private void LoadSrtVideoIntoGrid() { var factory = new DataRowFactory(GridTable); foreach (var entry in OpenSubRipFile.Entries) { DataRow dataRow = factory.Create(entry); GridTable.Rows.Add(dataRow); } }
private Type CreateRowType(RowType rowType, FacetInfo facets) { Dictionary <string, Type> members = new Dictionary <string, Type>(); foreach (EdmMember member in rowType.Members) { members.Add(member.GetColumnName(), this.Convert(member.TypeUsage)); } Type result = DataRowFactory.Create(members); return(result); }
private static Expression CreateDataRowSelector( Expression body, Expression[] memberSelectors) { Dictionary <string, Type> members = new Dictionary <string, Type>(); int index = 0; foreach (var selector in memberSelectors) { members.Add(string.Format("Item{0:D2}", index), selector.Type); index++; } Type rowType = DataRowFactory.Create(members); var helper = new DataRowKeyInfoHelper(rowType); body = helper.CreateKeyFactoryExpression(memberSelectors); return(body); }
public override Expression Visit(DbGroupByExpression expression) { Expression source = this.Visit(expression.Input.Expression); Type elementType = TypeHelper.GetElementType(source.Type); Type resultType = edmTypeConverter.GetElementType(expression.ResultType); Expression result = source; if (expression.Keys.Count == 0) { // This is a special case // The DbGroupByExpression does not contain any Key element // There is no GroupByClause List <Expression> constructorArguments = new List <Expression>(); for (int i = 0; i < expression.Aggregates.Count; i++) { DbFunctionAggregate aggregation = expression.Aggregates[i] as DbFunctionAggregate; if (aggregation == null) { throw new InvalidOperationException(expression.Aggregates[i].GetType().ToString() + "is not supported"); } Expression arg = this.CreateAggregateFunction( aggregation, //Aggregation is executed on the source expression.Input.GroupVariableName, elementType, source, resultType.GetProperties()[0].PropertyType); constructorArguments.Add(arg); } Expression aggregationResults = Expression.New( resultType.GetConstructors().Single(), constructorArguments.ToArray(), resultType.GetProperties()); // Wrap by a SingleResult collection object result = Expression.New( typeof(SingleResult <>).MakeGenericType(resultType).GetConstructors().Single(), aggregationResults); // Make it queryable result = queryMethodExpressionBuilder.AsQueryable(result); } else { // The properties of the selector form a subset of the properties of the result type // These properties defined first in the edm type PropertyInfo[] props = resultType.GetProperties(); Dictionary <string, Type> selectorProperties = new Dictionary <string, Type>(); // Collect the properties for (int i = 0; i < expression.Keys.Count; i++) { selectorProperties.Add(props[i].Name, props[i].PropertyType); } Type selectorType = DataRowFactory.Create(selectorProperties); LambdaExpression selector = null; ParameterExpression groupParam = Expression.Parameter(elementType, expression.Input.VariableName); using (this.CreateVariable(groupParam, expression.Input.VariableName)) { Expression[] keys = this.VisitExpressions(expression.Keys); selector = Expression.Lambda( this.CreateSelector(keys, selectorType), groupParam); } // Build the GroupBy call expression result = queryMethodExpressionBuilder.GroupBy(result, selector); // Get IGrouping<> type Type groupingType = TypeHelper.GetElementType(result.Type); // Collect argument initiators in an array Expression[] groupInit = new Expression[expression.Keys.Count + expression.Aggregates.Count]; ParameterExpression selectParam = Expression.Parameter(groupingType, "group"); Expression keyParam = Expression.Property(selectParam, "Key"); // Collect the Key arguments for (int i = 0; i < expression.Keys.Count; i++) { groupInit[i] = Expression.Property(keyParam, props[i].Name); } // Collect the aggregate arguments for (int i = 0; i < expression.Aggregates.Count; i++) { DbFunctionAggregate aggregate = expression.Aggregates[i] as DbFunctionAggregate; if (aggregate == null) { throw new InvalidOperationException(expression.Aggregates[i].GetType().ToString() + "is not supported"); } groupInit[expression.Keys.Count + i] = this.CreateAggregateFunction( aggregate, // Aggregation is executed on the group expression.Input.GroupVariableName, elementType, selectParam, props[expression.Keys.Count + i].PropertyType); } selector = Expression.Lambda( Expression.New( resultType.GetConstructors().Single(), groupInit, resultType.GetProperties()), selectParam); result = queryMethodExpressionBuilder.Select(result, selector); } return(result); }