DevExpress ASP (4) Use of-criteriaoperator

Source: Internet
Author: User

Original: DevExpress ASP (4) Use of-criteriaoperator

In the previous section, we've covered the use of Criteriaoperator expressions to get Object data.

Criteriaoperator criteria = Criteriaoperator.parse ("[userid]= '" + obj. UserID + "'"); Users objnew = session. Findobject<users> (criteria);

If the query results are multiple numbers, we can use Xpcollection to receive:

xpcollection<users> coll = new xpcollection<users> (session); Criteriaoperator criteria = Criteriaoperator.parse (""); SortProperty sortproperty = new SortProperty ("FirstName", sortingdirection.ascending); sortingcollection s = new sortingcollection (sortproperty); Coll. Session = Session;coll. Criteria = Criteria;coll. sorting = s;

Let's modify the example of the previous section with the following code:

Using system;using system.collections.generic;using system.configuration;using system.linq;using System.Text;using System.threading.tasks;using devexpress.data.filtering;using devexpress.xpo;using DevExpress.Xpo.DB;using Xpomodel.demodb;namespace devconsole{class Program {static void Main (string[] args) {str ing Provider = configurationmanager.connectionstrings["ConnectionString"]. connectionstring;//Get database connection Idatalayer DataLayer = new Simpledatalayer (Xpodefault.getconnectionprovider (provider , Autocreateoption.databaseandschema));//Build Data layer Xpo unique DevExpress.Xpo.Session Session = new DevExpress.Xpo.Sessio N (datalayer);                Bind data layer and session for (int i = 0; i < i++) {users obj = new users (session); Obj.                FirstName = "Dave_" + i.tostring (); Obj.                LastName = "Annable"; Obj.                Emailid = "[email protected]"; Obj.            Save (); } Xpcollection<users> coll = new xpcollection<users> (session);            Criteriaoperator criteria = Criteriaoperator.parse ("");            SortProperty sortproperty = new SortProperty ("FirstName", sortingdirection.ascending);            sortingcollection s = new sortingcollection (sortproperty); Coll.            session = Session; Coll.            criteria = criteria; Coll.            sorting = s; for (int j = 0; J < Coll. Count;                J + +) {Users obj = coll[j]; Console.WriteLine (String. Format ("id:{0},firstname:{1},lastname:{2}", obj. UserID, obj. FirstName, obj.            LastName));        } console.readline (); }    }}

After running the program, the console appears as follows:

Figure One execution query results

Criteriaoperator can also be applied to xpodatasource (subsequent references to how to use them).

The foreground adds the Xpodatasource control as follows:

<dx:xpodatasource id= "XpoDataSource1" runat= "Server" servermode= "True" typename= "XPOModel.DemoDB.Users" >< /dx:xpodatasource>

Background Code indicator Query filter conditions are as follows:

Xpodatasource1.session = Session; Xpodatasource1.criteria = "userid= ' 122008 '";

The effect of the presentation is as follows:

Figure II Xpodatasource results after filtering query execution

In the next section, we'll take a complete example of how to use the DevExpress control to implement CRUD operations with very little code ...

DevExpress ASP (4) Use of-criteriaoperator

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.