Shakky

Can anyone please tell me how to sort the related objects of a corresponding entity in.net client objects


Re: ADO.NET Data Services (Pre-Release) Sorting in Windows Application Datagrid with Astoria Client library

Pablo Castro - MSFT

Not sure I understood the question. If you bring a set of related objects down to the client (by using the Load() method in the collection object), then you can move them to a new list and sort them there...the collection that holds the related objects does not support sorting itself (astoria -just like relational databases- does not guanrantee the order of things that do not specifically have an orderby directive).

Pablo Castro

Technical Lead

Microsoft Corporation

http://blogs.msdn.com/pablo






Re: ADO.NET Data Services (Pre-Release) Sorting in Windows Application Datagrid with Astoria Client library

Shakky

As you said i tried sorting the related objects after moving them to a new list. But i got stuck up when passing arguments for the Orderby method(Orderby<TSource,Tkey>(Func<TSource,TKey>KeySelector, IComparer<TKey>)).

Can you please give me a sample for sorting.





Re: ADO.NET Data Services (Pre-Release) Sorting in Windows Application Datagrid with Astoria Client library

Galin Iliev

Hi Shakky,

take a look at 101 LINQ Samples:

there are mainly two ways to do it:

with LINQ query:

Code Block
List products = GetProductList();

var sortedProducts =
from p in products
orderby p.ProductName
select p;

and with OrderBy extension method:

Code Block

public class CaseInsensitiveComparer : IComparer
{
public int Compare(string x, string y)
{
return string.Compare(x, y, true);
}
}

public void Linq31() {
string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry"};

var sortedWords = words.OrderBy(a => a, new CaseInsensitiveComparer());

ObjectDumper.Write(sortedWords);

Hope this helps!




Re: ADO.NET Data Services (Pre-Release) Sorting in Windows Application Datagrid with Astoria Client library

Shakky

Thanks. It helped me to solve the problem.