예제 #1
0
        private QueryModelReference ComputeParameterModelReference(ParameterExpression parameter)
        {
            QueryModelReference modelReference = null;

            foreach (var node in this.GetExpressionTrail())
            {
                var methodCall = node as MethodCallExpression;
                if (methodCall == null)
                {
                    continue;
                }

                modelReference = this.GetModelReferenceForNode(node);
                if (modelReference == null)
                {
                    continue;
                }

                var method     = methodCall.Method;
                var sourceType = method.GetParameters()[0].ParameterType.FindGenericType(typeof(IEnumerable <>));
                var resultType = method.ReturnType.FindGenericType(typeof(IEnumerable <>));
                if (sourceType != resultType)
                {
                    // In case sourceType IEnumerable<Person> and resultType is
                    // IEnumerable <SelectExpandBinder.SelectAllAndExpand<Person>>
                    // or IEnumerable<SelectExpandBinder.SelectAll<Person>>
                    // or IEnumerable<SelectExpandBinder.SelectSome<Person>>
                    // or IEnumerable<SelectExpandBinder.SelectSomeAndInheritance<Person>>
                    if (sourceType == null || resultType == null)
                    {
                        continue;
                    }

                    var resultGenericType = resultType.GenericTypeArguments[0];
                    if (!resultGenericType.IsGenericType ||
                        resultGenericType.GenericTypeArguments[0] != sourceType.GenericTypeArguments[0])
                    {
                        continue;
                    }
                }

                var typeOfT = sourceType.GenericTypeArguments[0];
                if (parameter.Type == typeOfT)
                {
                    var collectionType = modelReference.Type as IEdmCollectionType;
                    if (collectionType != null)
                    {
                        modelReference = new ParameterModelReference(
                            modelReference.EntitySet,
                            collectionType.ElementType.Definition);
                        return(modelReference);
                    }
                }
            }

            return(modelReference);
        }
        private QueryModelReference ComputeParameterModelReference(ParameterExpression parameter)
        {
            QueryModelReference modelReference = null;
            foreach (var node in this.GetExpressionTrail())
            {
                var methodCall = node as MethodCallExpression;
                if (methodCall == null)
                {
                    continue;
                }

                modelReference = this.GetModelReferenceForNode(node);
                if (modelReference == null)
                {
                    continue;
                }

                var method = methodCall.Method;
                var sourceType = method.GetParameters()[0].ParameterType.FindGenericType(typeof(IEnumerable<>));
                var resultType = method.ReturnType.FindGenericType(typeof(IEnumerable<>));
                if (sourceType != resultType)
                {
                    // In case sourceType IEnumerable<Person> and resultType is
                    // IEnumerable <SelectExpandBinder.SelectAllAndExpand<Person>>
                    // or IEnumerable<SelectExpandBinder.SelectAll<Person>>
                    // or IEnumerable<SelectExpandBinder.SelectSome<Person>>
                    // or IEnumerable<SelectExpandBinder.SelectSomeAndInheritance<Person>>
                    if (sourceType == null || resultType == null)
                    {
                        continue;
                    }

                    var resultGenericType = resultType.GenericTypeArguments[0];
                    if (!resultGenericType.IsGenericType ||
                        resultGenericType.GenericTypeArguments[0] != sourceType.GenericTypeArguments[0])
                    {
                        continue;
                    }
                }

                var typeOfT = sourceType.GenericTypeArguments[0];
                if (parameter.Type == typeOfT)
                {
                    var collectionType = modelReference.Type as IEdmCollectionType;
                    if (collectionType != null)
                    {
                        modelReference = new ParameterModelReference(
                            modelReference.EntitySet,
                            collectionType.ElementType.Definition);
                        return modelReference;
                    }
                }
            }

            return modelReference;
        }