This section describes how to use the interfaces provided by Orm. Net to display data, including grouping and sorting.
Datamanager. Get [object] GET [object] collection methods
This is the main way to get data. It can be seen from the name that GetObject is to get an object, and getobjectcolletion is to read several rows of records to get an object set. The usage mode is as follows:
Object object = datamanager.Get [object]
Or
Objectcollection object = datamanager.Get [object] Collection
Reading a student named Tom
// create a new datamanager object with database connection string datamanager dm = New datamanager (config. DSN); // create the query to retrieve the desired information DM. querycriteria. and (joinpath. student. columns. firstname, "Tom" , matchtype. exact); // copy the resulting dataset from datamanger to a new student object Student = DM. getstudent (); // display the retrieved information console. writeline (student. firstname + "" + student. lastname);
If this is the case, a compilation error occurs, because getstudent returns student.
Contact contact = DM. getstudent ();
If you write an error to the root object (Root), an error will also be reported.
// Create the query to retrieve the desired informationDM. querycriteria. And (joinpath. Contact. Columns. address1,& Quot; 123 Main Street & quot", Matchtype. Exact );// Incorrect-cannot create and copy the root object contact from abve into a student object !!Student = DM. getstudent ();
Obtain all students whose surnames contain Jones
// create a new datamanager object with DSN Information datamanager dm = New datamanager (config. DSN); // clear any previous queries DM. querycriteria. clear (); // create the query DM. querycriteria. and (joinpath. student. columns. lastname, "Jones" , matchtype. exact); // copy the result dataset from datamanager as a collection of student objects instead of a single object studentcollection students = DM. getstudentcollection (); // loop through each student in the collection. foreach (student s in students) console. writeline ( "fullname: {0} {1}" , S. firstname, S. lastname);
You can also leave the querycriteria value unspecified before starting the query. As shown below, the querycriteria will query all data Row Records.
// Create a new datamanager object with DSN InformationDatamanager dm =NewDatamanager (config. DSN );// Return all students from the student table. Copy the result dataset from datamanager as a collection of student objects instead of // a single objectStudentcollection students = DM. getstudentcollection ();// Loop through each student in the collection.Foreach(Student sInStudents) console. writeline ("Fullname: {0} {1 }", S. firstname, S. lastname );
Datamanager. lastquerytext
After calling the datamanager method get [object] Or get [object] collection, you can read the attribute lastquerytext to return the last SQL query statement, as follows:
Studentcollection students = DM. getstudentcollection (); console. writeline ("Output SQL :"+ DM. lastquerytext );
Collection methods generated for each column Property
For the returned collection set, there are several ways to filter and sort it
Findby [property] (value) |
Searches for a set and returns an object. |
Filterby [property] (value) |
Return the filtered set based on input parameters. |
Sortby [property] (sortdirection) |
Sorts the set. The enumerated value is Sortdirection. ascending, sortdirection. Descending |
Find the student whose name is Karen from all the students
// Retrieve a single object from the cached collection where the first // name is 'karen'Student = DM. getstudentcollection (). findbyfirstname ("Karen"); Console. writeline ("Student name :"+ Student. firstname +""+ Student. lastname );// Or you can access the same information directlyConsole. writeline ("Test :"+ Students. findbyfirstname ("Karen"). Lastname );
Find all courses created on
// Filter the coursecollection to find courses created on 11/06/2002Coursecollection = courses. filterbydatecreated (datetime. parse ("11/06/2002"));
Search for all students and sort them by name in ascending order
Studentcollection students = DM. getstudentcollection (). sortbyfirstname (sortdirection. ascending );
Comparetype Enumeration
Remember to use the matchtype enumeration in querycriteria to match the required records. In the collection, comparetype is used for matching.
The followingCodeFragment, return to all students whose admission date is later
Studentcollection students = DM. getstudentcollection ();// Return all students from the table// Use filterby to return only students which have a datecreated value greater than 11/06/2002Studentcollection newstudents = students. filterbydatecreated (datetime. parse ("11/06/2002"), Comparetype. Greater );
The following table lists the enumerated values of comaretype.
Comparetype. Contains
|
Will search the database column thatPropertyMaps to and return all rows whereValueIs containedAnywhereWithin the column's value. |
Comparetype. endswith
|
Will search the database column thatPropertyMaps to and return all rows whereValueIs at the end of the column's value. |
Comparetype. Exact
|
Default-Will search the database column thatPropertyMaps to and return all rows where the column's value exactly matchesValue. |
Comparetype. Greater
|
Will search the database column thatPropertyMaps to and return all rows whereValueIs greater than the column's value. |
Comparetype. greaterorequal
|
Will search the database column thatPropertyMaps to and return all rows whereValueIs greater than or equal to the column's value. |
Comparetype. Lesser
|
Will search the database column thatPropertyMaps to and return all rows whereValueIs less than the column's value. |
Comparetype. lesserorequal |
Will search the database column thatPropertyMaps to and return all rows whereValueIs less than or equal to the column's value. |
Comparetype. Not |
Will search the database column thatPropertyMaps to and return all rows whereValueDoes not exactly match the column's value. |
Comparetype. notcontain |
Will search the database column thatPropertyMaps to and return all rows whereValueDoes not exactly match the column's value. |
Comparetype. startswith
|
Will search the database column thatPropertyMaps to and return all rows whereValueIs at the beginning of the column's value. |