public GenericQueryReader(ContentQueryTranslator translator, ContentResolver content, Resources resources,
                                  Func <ICursor, Resources, T> selector)
        {
            if (translator == null)
            {
                throw new ArgumentNullException("translator");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            this.translator = translator;
            this.content    = content;
            this.resources  = resources;
            this.selector   = selector;
        }
Пример #2
0
 internal ProjectionReader(ContentResolver content, ContentQueryTranslator translator,
                           Func <ICursor, int, T> selector)
 {
     this.content    = content;
     this.translator = translator;
     this.selector   = selector;
 }
        public GenericQueryReader(ContentQueryTranslator translator, ContentResolver content, Resources resources, Func <ICursor, Resources, T> selector, string defaultSort)
            : this(translator, content, resources, selector)
        {
            if (defaultSort == null)
            {
                throw new ArgumentNullException("defaultSort");
            }

            this.defaultSort = defaultSort;
        }
        Object IQueryProvider.Execute(Expression expression)
        {
            var translator = new ContentQueryTranslator(this, tableFinder);

            expression = translator.Translate(expression);

            if (translator.IsCount || translator.IsAny)
            {
                ICursor cursor = null;
                try
                {
                    String[] projections = (translator.Projections != null)
                  ? translator.Projections.Where(p => p.Columns != null).SelectMany(t => t.Columns).ToArray()
                  : null;

                    cursor = content.Query(
                        translator.Table,
                        projections,
                        translator.QueryString,
                        translator.ClauseParameters,
                        translator.SortString);

                    if (translator.IsCount)
                    {
                        return(cursor.Count);
                    }
                    else
                    {
                        return(cursor.Count > 0);
                    }
                }
                finally
                {
                    if (cursor != null)
                    {
                        cursor.Close();
                    }
                }
            }

            IQueryable q = GetObjectReader(translator).AsQueryable();

            //IQueryable q = GetObjectReader (null).AsQueryable();

            expression = ReplaceQueryable(expression, q);

            if (expression.Type.IsGenericType && expression.Type.GetGenericTypeDefinition() == typeof(IOrderedQueryable <>))
            {
                return(q.Provider.CreateQuery(expression));
            }
            else
            {
                return(q.Provider.Execute(expression));
            }
        }
 protected abstract IEnumerable GetObjectReader(ContentQueryTranslator translator);
 internal MultiProjectionReader(ContentResolver content, ContentQueryTranslator translator)
 {
     this.content    = content;
     this.translator = translator;
 }