extract elements from xml document - windows-phone-7

I have an xml document in which I want to extract every 10 elements. I used this code to extract the last 10 elements, but the idea is to get the next 10 ones just before them, I can't use pagination with linq since I get the whole document:
slideView.ItemsSource =
(from channel in xmlItems.Descendants("album")
orderby (int)channel.Element("catid") descending
select new onair
{
title = (string)channel.Element("name"),
photo = (string)channel.Element("picture")
}).Take(10);
any ideas please?
Thanks

Try .Skip(10).Take(10) towards the end of your query.

Related

How to get uniques and sum based on criteria set in Google Sheets?

I'm trying to get these summed, but I can't wrap my head around it.
Here is a visual demo:
Here is the link to the sheet, in case you feel like jumping in:
https://docs.google.com/spreadsheets/d/1gh5w0czg2JuoA3i5wPu8_eOpC4Q4TXIRhmUrg53nKMU/edit?usp=sharing
I did an INDEX+MATCH, but of course this isn't going to get me anywhere:
=iferror(INDEX(E:E;MATCH(1;(F:F=I$6)*(A:A=$H$7);0));"-")
You can do two nested QUERY to find the uniques (by counting them), and only selecting them the column of numbers. The first QUERY also filters by date and type:
=SUM(QUERY(QUERY(A:F;"SELECT A,B,E,COUNT(A) where A = '"&H7&"' AND F = date'"&TEXT(I6;"yyyy-mm-dd")&"' group by A,B,E");"SELECT Col3"))
As an array to include more all the dates:
=MAKEARRAY(2;COUNTA(I6:6);LAMBDA(r;c;SUM(QUERY(QUERY(A:F;"SELECT A,B,E,COUNT(A) where A = '"&INDEX(H7:H8;r)&"' AND F = date'"&TEXT(INDEX(I6:6;;c);"yyyy-mm-dd")&"' group by A,B,E");"SELECT Col3"))))
Added working solution to your sheet here:
=MAKEARRAY(2;COUNTA(I6:O6);LAMBDA(r;c;SUM(LAMBDA(z;MAP(INDEX(z;;1);INDEX(z;;2);INDEX(z;;3);LAMBDA(a;e;f;IFNA(FILTER(e;a=INDEX(H7:H8;r);f=INDEX(I6:O6;;c))))))(UNIQUE({A:A\E:E\F:F})))))

Get newest date in Sheet

i have a sheet with two tabs. In the first tab, i can select a site and i have a list of types. I have a second tab with many datas from each type (date, year, month week, and site attached to a type).
I would like in the first tab write a formula to automatically get the newest date of the type depending to the selected site.
I'm not good with formulas but i tried to write one, this one =IF((AND(C1=DATA!F:F),(B3=DATA!E:E)),LARGE(DATA!A:A),"") but i don't have result.
Anyone can help me with my problem please ? This is the link of my Sheet.
=INDEX(SORT(FILTER( DATA!A:A; DATA!F:F = $C$1; DATA!E:E = $B3); 1; FALSE);1)
=INDEX(SORT(FILTER( DATA!A:A; DATA!F:F = $C$1; DATA!E:E = $B4); 1; FALSE);1)
INDEX(array, [row])
Index gets the nth value in an array, when you pass in the value 1, it will get the top most value.
I created a sorted array by using the FILTER function. and the SORT function. I sorted it descending and only returned the dates in the FILTER function.

Ruby on Rails: Active-Record sort and put specific row to the top

I have an Active record one -> many association and I need to get all child rows starting with a specific row
something like
parent.children.startwith(some_child_row_id)
Is there a one-liner?
Edit:
For more Clarity
Let say we have an array
a = ["a","b" ,"cg", "d","e"]
I want "cg" to be first element.
I'll do somthing like
element = a.delete("cg") // array will be ["a","b","d","e"]
a.unshift(element) // array will now become ["cg","a","b","d","e"]
See! An element is moved to index 0.
I want the same in case of ActiveRecord rows, Preferably a One-liner.
I suppose conditional ordering will do the trick.
parent.children.order("CASE WHEN (id = #{some_child_row_id}) THEN 0 ELSE 1 END ASC, id")
It's pretty simple actually.
All you need is to apply a where clause to the children of your parent.
Try something like this.
parent.children.where('id > ?', start_row)
I believe this is what you were looking for. Hope this helps.

Linq comparing DataTable with List<String>

I have a string list (List) that contains delimited fields. An example would be:
List[0] = "7/1/2013,ABC,123456"
List[1] = "7/2/2013,DEF,234567"
I also have a DataTable where a record either will or will not contain the the values from the 2nd and 3rd column in the String List:
Example
Row[0][0]="ABC" <-----String
Row[0][1]=123456 <-----Int32
What I want to do is find any records (via Linq) in the DataTable that DO NOT have corresponding values in the String List.
I've been googling for a while, and can't quite find the right way to do this with Linq...can anyone help?
This code snippet should give you an enumeration of the indices that do not have the appropriate DataTable values:
var correspondingRecords =
from index in Enumerable.Range(0, List.Count)
let items = List[index].Split(',')
where !(item[1] == Row[index][0] && item[2] == Row[index][1])
select index;
The basic idea is to iterate over the indices in order to make sure that you're comparing the appropriate rows and list items to one another. Once you do that, it's simple enough to parse the list item and make the appropriate comparisons.

Linq Paging - How to incorporate total record count

I am trying to figure out the best way of getting the record count will incorporating paging. I need this value to figure out the total page count given a page size and a few other variables.
This is what i have so far which takes in the starting row and the page size using the skip and take statements.
promotionInfo = (from p in matches
orderby p.PROMOTION_NM descending
select p).Skip(startRow).Take(pageSize).ToList();
I know i could run another query, but figured there may be another way of achieving this count without having to run the query twice.
Thanks in advance,
Billy
I know i could run another query, but figured there may be another way of achieving this count without having to run the query twice.
No, you have to run the query.
You can do something like:
var source = from p in matches
orderby p.PROMOTION_NM descending
select p;
var count = source.Count();
var promotionInfo = source.Skip(startRow).Take(pageSize).ToList();
Be advised, however, that Skip(0) isn't free.

Resources