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