New Posts New Posts RSS Feed: Silverlight: Dynamic OrderBy
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Silverlight: Dynamic OrderBy

 Post Reply Post Reply
Author
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Topic: Silverlight: Dynamic OrderBy
    Posted: 29-Jul-2010 at 10:43am
Well, I used the term "test" quite loosely - I ran a single query and it worked.  Here's the query -
     var customersQuery = _em1.Customers
        .Where(c => c.ContactTitle == "Sales Representative")
        .OrderBy("CompanyName")
        as EntityQuery<Customer>;
   
      _em1.ExecuteQueryAsync<Customer>(customersQuery, GotCustomers, null);
 
The changes to the DynamicLibrary were hacks, just to see if the code would compile.  I'll post it here, but I want to emphasize this is neither tested nor endorsed by IdeaBlade, and certainly not supported - it's just my hacking to try the DL in Silverlight.
 
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post Posted: 29-Jul-2010 at 9:24am
Do you have the code that you test with?
 
Thanks for the info. I'll give it a try.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jul-2010 at 8:46am
Actually, some of it does.  The ClassFactory does not work in Silverlight, along with the CreateClass methods on DynamicExpression, but if you remove or comment all that out you can get the DynamicLibrary working.   I only tested the dynamic OrderBy so don't know what else might fail at run time, but this library is pretty handy.
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jul-2010 at 12:34pm
FYI: This does not work with Silverlight
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post Posted: 23-Jul-2010 at 4:31pm
found it.
 
Will this work with Silverlight?
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post Posted: 23-Jul-2010 at 3:59pm
Sorry but the link is no good.

Edited by jkowalski - 23-Jul-2010 at 4:00pm
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 23-Jul-2010 at 3:45pm
You might find something here:

LINQ Dynamic Query Library
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post Posted: 23-Jul-2010 at 1:04pm

There has got to be a better way to dynamically order a Silverlight Blade query.

 

Please advise.

 
 
var accounts = (IEntityQuery<Account>)accountQuery;

var orderedQuery = accounts.OrderBy(a => a.AccountName);

 

if(DefaultSortDirection == ListSortDirection.Ascending)

{

    switch (DefaultSortColumn.ToLower())

    {

        case "accountname":

            orderedQuery = accounts.OrderBy(a => a.AccountName);

            break;

        case "accountid":

            orderedQuery = accounts.OrderBy(a => a.AccountID);

            break;

        case "accountsubtype":

            orderedQuery = accounts.OrderBy(a => a.AccountSubtype);

            break;

        case "accounttype":

            orderedQuery = accounts.OrderBy(a => a.AccountType);

            break;

        case "address1":

            orderedQuery = accounts.OrderBy(a => a.Address1);

            break;

        }

}

else

{

    switch (DefaultSortColumn.ToLower())

    {

    case "accountname":

        orderedQuery = accounts.OrderByDescending(a => a.AccountName);

        break;

    case "accountid":

        orderedQuery = accounts.OrderByDescending(a => a.AccountID);

        break;

    case "accountsubtype":

        orderedQuery = accounts.OrderByDescending(a => a.AccountSubtype);

        break;

    case "accounttype":

        orderedQuery = accounts.OrderByDescending(a => a.AccountType);

        break;

    case "address1":

        orderedQuery = accounts.OrderByDescending(a => a.Address1);

        break;

    }

}

 

return orderedQuery;

 

 

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down