public IEnumerable <T> Query(Expression <Func <T, bool> > query, int top = 100, int skip = 0)
        {
            List <T> results = new List <T>();

            string whereSection = CamlMapper.Translate(query.Body, query.Parameters.FirstOrDefault());

            CamlQuery caml = new CamlQuery();

            caml.ViewXml = ComposeQuery(whereSection, top);
            if (Position != null && skip != 0)
            {
                if (skip - PreviousSkip > top)
                {
                    return(results);
                }
                if (PreviousSkip != skip - top)
                {
                    throw new NotImplementedException("Unable to skip. Using SPClientRepository You can skip only one page!");
                }

                PreviousSkip += top;
                caml.ListItemCollectionPosition = Position;
            }

            ListItemCollection collection = List.GetItems(caml);

            Context.Load(collection);
            Context.ExecuteQuery();
            foreach (ListItem item in collection)
            {
                results.Add(ItemMappingHelper.MapFromItem <T>(item));
            }
            Position = collection.ListItemCollectionPosition;
            return(results);
        }
        public T GetById(int id)
        {
            ListItem item = List.GetItemById(id);

            Context.Load(item);
            Context.ExecuteQuery();

            return(ItemMappingHelper.MapFromItem <T>(item));
        }
Exemple #3
0
        public static void EnumerateListItems <T>(List list, string query, Action <T> action, int rowLimit = 100) where T : new()
        {
            int top = 0;
            ListItemCollectionEnumerable liEnumerable = new ListItemCollectionEnumerable(list, query, 100);

            foreach (ListItemCollection collection in liEnumerable)
            {
                foreach (ListItem item in collection)
                {
                    action(ItemMappingHelper.MapFromItem <T>(item));
                    top++;
                    if (top >= rowLimit)
                    {
                        return;
                    }
                }
            }
        }