예제 #1
0
        public bool TryCreateKeyInfoHelper(Type keyType, out IKeyInfoHelper result)
        {
            if (!typeof(DataRow).IsAssignableFrom(keyType))
            {
                result = null;
                return(false);
            }

            result = new DataRowKeyInfoHelper(keyType);
            return(true);
        }
예제 #2
0
        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;
        }
        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);
        }