Next, we introduce the save operation of the Xpo object through a console application.
Figure one adding a new project
Figure II Selecting the project type as a console application
View the generated Program.cs code file with the following code:
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace devconsole{ class program { static void Main (string[] args) { } }}
In order to use the Xpo object, we need to add two DLL files, respectively:
Devexpress.data.v12.2.dll
Devexpress.xpo.v12.2.dll
After installing DevExpress, you can find it in the DevExpress installation directory.
Add Xpomodel at the same time so that the console program can use the Xpo object.
Figure III Adding a reference operation
Figure IV Adding a reference to the project Xpomodel
Figure v after referencing a DLL
Add the following code, use the Xpo object to save the users, before we go back to the previous section of the generated users.cs,users has a default session constructor,
This session is not a client session in our traditional sense, but a DevExpress.Xpo.Session.
Using system;using devexpress.xpo;using devexpress.data.filtering;namespace xpomodel.demodb{public Partial Class users {public users (session session): base (session) {} public override void Afterconstruction () {BAS E.afterconstruction (); } }}
Therefore, we create the object instance by using new DevExpress.Xpo.Session () as the default constructor parameter.
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Using Xpomodel.demodb;namespace devconsole{ class program { static void Main (string[] args) { Users obj = new users (new DevExpress.Xpo.Session ()); Obj. FirstName = "Dave"; Obj. LastName = "Annable"; Obj. Emailid = "[email protected]"; Obj. Save (); Console.Write ("The object has been saved by Xpo Object!") "); Console.ReadLine ();}}}
After running the console program, the display object has been saved successfully
Figure VI Console program run results
So where did the object data go, and we found an Access file named DevConsole.vshost.mdb in the console program root directory,
Figure seven Auto-generated Access database files
After opening the Access file, we see the data that has been saved, as shown in:
Figure Eight opening an Access database to show that the insert operation succeeded
At this point, we have completed the save operation for the Xpo object to the default Access database.
This doesn't seem to be the location where we want to save the data, we don't have the database that created SQL Server in the first section, why didn't we save the data to SQL Server?
In the next section, we continue ...
DevExpress ASP (2) Use of-xpo objects (save action)