New Posts New Posts RSS Feed: Server side/Client side
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Server side/Client side

 Post Reply Post Reply
Author
tj62 View Drop Down
Groupie
Groupie
Avatar

Joined: 21-May-2009
Location: Iceland
Posts: 81
Post Options Post Options   Quote tj62 Quote  Post ReplyReply Direct Link To This Post Topic: Server side/Client side
    Posted: 25-Sep-2009 at 6:26am
Hi, I'm quite new to Silverlight and DevForce . I fully understand how I can do LINQs to Entities at client side. However in my applications I have many queries that are of such nature that I have to do many queries first before I return the real data to the client. It is obvious that it is more appropirate doing all those server side to minimize round trips from client to server: Here is a small example I did for tesint using a console app.:
 
private static void GetCustomers(string userID)
{
 var userQ = (from user in m_mgr.EntUserSet
                      where user.p_userID == userID
                      select new {user, userGroups = user.p_UserGroups}).FirstOrDefault();
 var userGroups = (from u in userQ.userGroups
                               select u.p_userID).ToList();
 userGroups.Add(userID);
 var customerIDs = m_mgr.EntPointGroupAccessSet
                              .WhereIn( e => e.p_userID , userGroups )
                               .Select( e => new {customerID = e.p_customerID} ).Distinct();
 var customerQ = m_mgr.EntCustomerSet
                            .OrderBy(c => c.p_name)
                            .WhereIn(c => c.p_customerID, (from d in customerIDs select d.customerID).ToArray());
 foreach( EntCustomer c in customerQ )
 {
  Console.WriteLine( "Customer = " + c.p_name );
  Console.WriteLine();
 }
}
 
Now I want to move this functionalety to my Sileverlight app. Only the result of customerQ (the red one) is of importance at the client side. It would be redicelous to run the other 3 queries on client side that are only used to get parmeters for the customerQ.
What is the best practise to implement such server side functions (GetCustomers(string userID)) server side and how to call those client side. Probably it is right to call InvokeServerMethodAsync() used client side, but how and where should I implement the GetCustomers(string userID) server side? Should it be implemented as a member of EntCustomers?...hardly becuase do not have anyaccess to EnCustomerSet there.

PS: the WhereIn function above is a "QueriableExetension" to implement the common IN of SQL not currently available in LINQ to entites...This only creates an Or-squence.
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: 25-Sep-2009 at 12:15pm
Originally posted by tj62

I have many queries that are of such nature that I have to do many queries first before I return the real data to the client. It is obvious that it is more appropirate doing all those server side to minimize round trips from client to server


It is often possible to string together what you might otherwise consider multiple queries, so that the entire expression can be submitted to the server in a single SQL statement. E.g.,

     var query = _mgr.Customers.Where(c=>c.Country == "Brazil");
     var query2 = query.SelectMany(c=>c.Orders);

can be written as

     var query = _mgr.Customers.Where(c=>c.Country == "Brazil").SelectMany(c=>c.Orders);

and so forth.

Originally posted by tj62

:
Probably it is right to call InvokeServerMethodAsync() used client side, but how and where should I implement the GetCustomers(string userID) server side? Should it be implemented as a member of EntCustomers?...hardly
because I do not have any access to EntCustomerSet there.


Yes, you do have access to EntCustomerSet. The server method gets an EntityManager parameter.
You can do any series of queries or other operations in your server-side method, then return any result.


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down