Print Page | Close Window

Server side/Client side

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1495
Printed Date: 17-Apr-2025 at 10:31am


Topic: Server side/Client side
Posted By: tj62
Subject: Server side/Client side
Date 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.



Replies:
Posted By: GregD
Date 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.





Print Page | Close Window