Original: DevExpress ASP (1) Creation of-XPO model
This series introduces DevExpress ASP through a number of simple examples. NET control is used. Let's introduce the use of XPO, install the devexpress version of DXperienceUniversal-12.2.4, and use visual Studio 2012+sql Server2005.
What is XPO?
XPO is the abbreviation for EXpress persistent objects, an ORM tool that is launched by DevExpress company on the. Netframwork platform. Persistent objects translates "persistent object" meaning, so-called persistence, that is, the data stored, such as the existence of databases, files, such as the form of "permanent" preservation. XPO is an ORM tool that plays a middle-tier role between the application code and the database, acting as an intermediate bridge, simply by mapping objects created by object-oriented programming to a database that has a one by one corresponding relationship with the tables in the database. In object-oriented programming, we only need to be concerned with the "object" in the program, and XPO will automatically react to the operation of our object to the database.
The installation process is skipped here ...
After the installation is successful, the VS2012 new project will have the installed devexpress Category option, as shown in:
(Figure I) Create a new solution
(figure II) Adding a class library project
(figure III) establishing the XPO ORM Model Wizard
(Figure IV) choose to map to an existing database
Select the database, enter Username,password, check the guide and stored procedure, and the stored procedure selection interface will appear in the next step.
(Figure VI) confirm the selected table
(Figure Seven) confirm the selected stored procedure
(Figure eight) settings for database tables, field prefixes, suffixes, and so on
(Fig. Nine) complete
(Figure 10) New model not saved interface
(Figure 11) After the new model is saved, generate the Xxxcode directory
(Figure 12) Generate Code directory structure
Auto-generated code:
ConnectionHelper.cs
Using system;using devexpress.xpo;using devexpress.data.filtering;namespace xpomodel.demodb{public static class Conne Ctionhelper {Public const string ConnectionString = @ "Xpoprovider=mssqlserver;data source=.; User Id=demo;password=demo;initial Catalog=demodb; Persist Security info=true "; public static void Connect (DevExpress.Xpo.DB.AutoCreateOption autocreateoption) {Xpodefault.datalayer = Xpodefault.getdatalayer (ConnectionString, autocreateoption); Xpodefault.session = null; } public static DevExpress.Xpo.DB.IDataStore Getconnectionprovider (DevExpress.Xpo.DB.AutoCreateOption autocreateopt ION) {return Xpodefault.getconnectionprovider (ConnectionString, autocreateoption); } public static DevExpress.Xpo.DB.IDataStore Getconnectionprovider (DevExpress.Xpo.DB.AutoCreateOption autocreateopt Ion, out idisposable[] objectstodisposeondisconnect) {return Xpodefault.getconnectionprovIder (ConnectionString, autocreateoption, out objectstodisposeondisconnect); } public static Idatalayer Getdatalayer (DevExpress.Xpo.DB.AutoCreateOption autocreateoption) {RE Turn Xpodefault.getdatalayer (ConnectionString, autocreateoption); } }}
storedprochelper.cs
Using system;using devexpress.xpo;using devexpress.data.filtering;namespace xpomodel.demodb{public static class Sproc Helper {public static DevExpress.Xpo.DB.SelectedData Execaspnetpager (session session, int pageSize, int curpage , string viewName, String fieldName, String OrderField, String OrderType, String where1) {return Sessio N.executesproc ("", New Operandvalue (pageSize), New Operandvalue (Curpage), New Operandvalue (ViewName), new Operandvalue (FieldName), New Operandvalue (OrderField), New Operandvalue (OrderType), New Operandvalue (Where1)); } public static DevExpress.Xpo.DB.SelectedData Execselectjqgridusers (session session, int PageIndex, String sortcol Umnname, string sortorderby, int numberofrows) {return session. Executesproc ("Selectjqgridusers", New Operandvalue (PageIndex), New Operandvalue (Sortcolumnname), New Operandvalue ( Sortorderby), New Operandvalue (numberofrows)); } public static System.collectioNs. Generic.icollection<selectjqgridusersresult> Execselectjqgridusersintoobjects (Session session, int PageIndex , string sortcolumnname, string sortorderby, int numberofrows) {return session. Getobjectsfromsproc<selectjqgridusersresult> ("Selectjqgridusers", New Operandvalue (PageIndex), new Operandvalue (Sortcolumnname), New Operandvalue (Sortorderby), New Operandvalue (numberofrows)); } public static Xpdataview Execselectjqgridusersintodataview (session session, int PageIndex, String sortcolumnname, string Sortorderby, int numberofrows) {DevExpress.Xpo.DB.SelectedData Sprocdata = session. Executesproc ("Selectjqgridusers", New Operandvalue (PageIndex), New Operandvalue (Sortcolumnname), New Operandvalue ( Sortorderby), New Operandvalue (numberofrows)); return new Xpdataview (session. Dictionary, session. GetClassInfo (typeof (Selectjqgridusersresult)), sprocdata); } public static void ExecselectjqgridusersintodataviEW (Xpdataview DataView, session session, int PageIndex, string sortcolumnname, string sortorderby, int numberofrows) {DevExpress.Xpo.DB.SelectedData Sprocdata = session. Executesproc ("Selectjqgridusers", New Operandvalue (PageIndex), New Operandvalue (Sortcolumnname), New Operandvalue ( Sortorderby), New Operandvalue (numberofrows)); Dataview.populateproperties (session. GetClassInfo (typeof (Selectjqgridusersresult))); Dataview.loaddata (Sprocdata); } }}
Users.cs
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 (); } }}
Users.Designer.cs
Using system;using devexpress.xpo;using devexpress.data.filtering;namespace xpomodel.demodb{public partial class User s:xpliteobject {int fuserid; [Key (TRUE)] public int UserID {get {return fuserid;} set {setpropertyvalue<int> ("UserID", ref fuserid, value);} } string Fusername; [Size] public string UserName {get {return fusername;} set {setpropertyvalue<string> ("UserName", ref fusername, value);} } string Ffirstname; [Size] public string FirstName {get {return ffirstname;} set {setpropertyvalue<string> ("FirstName", ref ffirstname, value);} } string Flastname; [Size] public string LastName {get {return flastname;} set {setpropertyvalue<string> ("LastName", ref flastname, value);} } string FmidDlename; [Size] public string MiddleName {get {return fmiddlename;} set {setpropertyvalue<string> ("MiddleName", ref fmiddlename, value);} } string Femailid; [Size] public string Emailid {get {return femailid;} set {setpropertyvalue<string> ("Emailid", ref femailid, value);} } }}
Now that the creation of the database to the XPO model has been completed, let's start with the Xpo object and see what it brings to us.
In the next section, we continue to use XPO, combined with Xpodatasource and Aspxgridview, to complete a single-table crud operation with minimal code.
-------------------------------------------------------------------------------------------------------
With the database script for the sample database, using SQL SERVER2005 databases, the SQL statements are as follows:
CREATE DATABASE [Demodb] on PRIMARY (NAME = n ' demodb ', FILENAME = N ' C:\DemoDB.mdf ', SIZE = 3072KB, filegrowth = 1024KB LOG on (NAME = n ' demodb_log ', FILENAME = N ' C:\DemoDB_log.ldf ', SIZE = 1024KB, filegrowth = 10%) goexec DBO.SP_DBCMPTL Evel @dbname =n ' Demodb ', @new_cmptlevel =90goif (1 = fulltextserviceproperty (' isfulltextinstalled ')) beginexec [Demodb] . [dbo]. [sp_fulltext_database] @action = ' Disable ' endgoalter database [Demodb] SET ansi_null_default OFF goalter Database [Demodb ] SET ANSI_NULLS off Goalter database [Demodb] set ANSI_PADDING off Goalter DATABASE [Demodb] SET ansi_warnings OFF goalte R DATABASE [Demodb] set ARITHABORT off Goalter database [Demodb] set auto_close OFF goalter database [Demodb] set Auto_cre Ate_statistics on Goalter database [Demodb] set auto_shrink OFF goalter database [Demodb] set auto_update_statistics on GO ALTER database [Demodb] set cursor_close_on_commit OFF goalter DATABASE [Demodb] set Cursor_default GLOBAL goalter Databa SE [Demodb] SET Concat_nUll_yields_null off Goalter database [Demodb] set Numeric_roundabort off Goalter database [Demodb] SET QUOTED_IDENTIFIER O FF goalter Database [Demodb] set Recursive_triggers off Goalter DATABASE [Demodb] set Auto_update_statistics_async OFF GOA Lter database [Demodb] set date_correlation_optimization OFF goalter DATABASE [Demodb] set PARAMETERIZATION simple Goalter Database [Demodb] set read_write goalter database [Demodb] set RECOVERY full Goalter DATABASE [Demodb] set Multi_user G Oalter DATABASE [Demodb] SET page_verify CHECKSUM gouse [Demodb]goif not EXISTS (SELECT name from Sys.filegroups WHERE is _default=1 and name = N ' PRIMARY ') ALTER DATABASE [Demodb] MODIFY FILEGROUP [PRIMARY] defaultgouse [demodb]go/****** Object : Table [dbo]. [Users] Script date:2014/11/27 13:36:56 ******/set ansi_nulls ongoset quoted_identifier ongocreate TABLE [dbo]. [Users] ([UserID] [int.] IDENTITY (null,[username] [nvarchar] () null,[firstname] [nvarchar] (null,[lastname) [ NVARCHAR] (NUL)L,[middlename] [nvarchar] (a) null,[emailid] [nvarchar] (+) NULL, CONSTRAINT [pk_users] PRIMARY KEY CLUSTERED ([UserID] A SC) with (Pad_index = off, Statistics_norecompute = off, Ignore_dup_key = off, Allow_row_locks = on, allow_page_locks = ON) On [PRIMARY]) on [Primary]go
DevExpress ASP. (1)-xpo model creation