Ejemplo n.º 1
0
        protected override Predicate TypedTranslate(PredicateConverter parent, ConstantExpression linq)
        {
            var queryOfT = (linq.Value as ObjectQuery);

            if (queryOfT != null)
            {
                return(parent.TranslateInlineQueryOfT(queryOfT));
            }

            var values = linq.Value as IEnumerable;

            if (values != null)
            {
                var elementType = linq.Type.GetNonEnumElementType();
                if ((elementType != null) && (elementType != linq.Type))
                {
                    var expressions = new List <Expression>();
                    foreach (var o in values)
                    {
                        expressions.Add(Expression.Constant(o, elementType));
                    }
                    return(parent.TranslateExpression(Expression.NewArrayInit(elementType, expressions)));
                }
            }

            return(PredicateBuilder.Constant(linq.Value));
        }