示例#1
0
        /// <summary>Creates and executes a DataServiceQuery based on the passed in expression which results a single value</summary>
        /// <typeparam name="TElement">generic type</typeparam>
        /// <param name="expression">The expression for the new query</param>
        /// <returns>single valued results</returns>
        internal TElement ReturnSingleton <TElement>(Expression expression)
        {
            IQueryable <TElement> query = new DataServiceQuery <TElement> .DataServiceOrderedQuery(expression, this);

            MethodCallExpression mce = expression as MethodCallExpression;

            Debug.Assert(mce != null, "mce != null");

            SequenceMethod sequenceMethod;

            if (ReflectionUtil.TryIdentifySequenceMethod(mce.Method, out sequenceMethod))
            {
                switch (sequenceMethod)
                {
                case SequenceMethod.Single:
                    return(query.AsEnumerable().Single());

                case SequenceMethod.SingleOrDefault:
                    return(query.AsEnumerable().SingleOrDefault());

                case SequenceMethod.First:
                    return(query.AsEnumerable().First());

                case SequenceMethod.FirstOrDefault:
                    return(query.AsEnumerable().FirstOrDefault());

#if !ASTORIA_LIGHT
                case SequenceMethod.LongCount:
                case SequenceMethod.Count:
                    return((TElement)Convert.ChangeType(((DataServiceQuery <TElement>)query).GetQuerySetCount(this.Context), typeof(TElement), System.Globalization.CultureInfo.InvariantCulture.NumberFormat));
#endif
                default:
                    throw Error.MethodNotSupported(mce);
                }
            }

            // Should never get here - should be caught by expression compiler.
            Debug.Assert(false, "Not supported singleton operator not caught by Resource Binder");
            throw Error.MethodNotSupported(mce);
        }
示例#2
0
 internal override Expression VisitMethodCall(MethodCallExpression m)
 {
     throw Error.MethodNotSupported(m);
 }