NoteDevexpressData Persistence Layer in
Persistent data objects:
Devexpress. xpo The data persistence objects in are mainly Xpobject And Xpbaseobject , The difference between them is Xpbaseobject Define a master ID From Xpobject The inherited object is stored in Oid Master ID If you already have a ready-made data table and a master ID From Xpbaseobject Derive your data persistence object.
Data access layer:
DevexpressThe data access layer in is encapsulated inSessionIs used by default.Devexrepss. xpo. session. defaultssessionYou can set the defaultSessionTo complete some basic settings of the data access layer, such as database link strings.
Data Operations:
There are many data operations, generally inXpbaseobjectAnd the query operation is not on the data persistence layer, but on the data layerDevexpress. DataHere, there are some very detailed data operations, you can perform bit operations on the data, you can also perform some advanced operations such as query classification. It's no wonder why some of its advanced controls, suchXforwartgrid, gridcontrolAnd so on. Of course, these data operation controls mainly use custom data to pass through the view to make the operation easy.
Some referencesCode:
1. Data Persistence class:
Public Class T_user: xpbaseobject
{
Fields & Properties # Region Fields & Properties
Protected String _ Loginname;
Protected Int _ Userid;
Public String Loginname
{
Get {Return This. _ Loginname ;}
Set {This. _ Loginname=Value ;}
}
[Key ( True )] // Use features to map data
Public Int Userid
{
Get {Return This. _ Userid ;}
Set {This. _ Userid=Value ;}
}
Public T_user ()
{
// Use this constructor when you want to create a new object.
// Place here your initialization code.
This . _ Parentid = - 1 ;
This . _ Regdate = Datetime. now;
}
Public T_user (session ): Base (Session) {
//This constructor is used when an object is loaded from a persistent storage.
//Do not place any code here.
}
}
2. Set the default Link
Xpodefault. connectionstring = Mssqlconnectionprovider. getconnectionstring ( " Server " , " Userid " , " PWD " , " DB " );
Of course, it also has other link drivers available.
3. test:
Try
{
Webad. Controls. t_user m_user = New Webad. Controls. t_user ();
M_user.loginname = " Apple " ;
M_user.password = " Test " ;
M_user.save ();
}
Catch (Exception ex)
{
System. Diagnostics. Debug. writeline (ex. Message );
}
From the perspective of the entire structure, devexpress's data persistence layer should be quite good. On the one hand, it can greatly simplify developers' coding work, while the Code of data persistence objects is mechanized, you can write a tool.
Simple note!