[Silverlight Study Notes] About using WCF Ria service for communication and obtaining data on the client

Source: Internet
Author: User

In the implementation of client SilverlightProgramIt is most convenient to use the WCF Ria service of Silverlight 4.0 when communicating with the server to obtain data, you can configure the server very quickly and then use the following method to obtain the corresponding data in the client Silverlight program: (the database table operated is user, the domain service class file corresponding to the server is userdomainservice)

Userdomaincontext context = new userdomaincontext (); <br/> entityquery <user> query = context. getuserquery (); <br/> loadoperation load = context. load <user> (query); <br/> mylistbox. itemssource = load. entities; // or context. users, etc. 

Now we will explain why loadoperation and entityquery are required. Instead of directly defining the userdomaincontext instance, we can directly obtain data through context. Users:

1. directly define the instance context of userdomaincontext, and then use or context. users, context. entitycontainer. getentityset <user> () and other methods to directly obtain the dataset. In this way, no data is obtained, that is, the count of the dataset is 0, and the data must pass context. load <user> (query) can load data to the userdomaincontext context. users, load. entities and other methods to obtain the dataset.

2. Why does entityquery be required?

Context. getuserquery () returns a queryable dataset called entityquery <user>. The queryable dataset defines loadoperation rules for loading data, for example:

Entityquery <user> query = context. getuserquery (); <br/> loadoperation load = context. Load <user> (query ); 

In this case, context. Users and load. Entities obtain all records in the user data table, similar to select * from user.

The following figure shows how to perform a proper LINQ query on entityquery:

Entityquery <user> query = from V in context. getuserquery () Where v. username = "sa" select V; <br/> loadoperation load = context. load <user> (query ); 

Then, use context. the load method asynchronously loads the data that meets the above-mentioned LINQ conditions. users, load. the dataset obtained by entities is a user record whose username is equal to SA, similar to select * from user where username = 'sa '.

3. Why loadoperation?

Through the above description, we also learned that the loadoperation <user> instance is returned after being asynchronously loaded through context. Load <user> (query. Now that asynchronous loading is required, we usually do some aftercare after the loading is complete. In this case, we can add the load. the completed event triggers this event when asynchronous loading is complete to complete our aftermath.

PS:

1. To use the WCF Ria service, you must install Silverlight tools 4.0 and search for it on the official website.

2, WCF Ria service tutorial can see this page: http://www.silverlightchina.net/html/zhuantixilie/getstart/2010/0815/1761.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.