DevexPress Persistent Object V.1.5 Learning Notes (1)

zhaozj2021-02-16  77

The famous Delphi Third-Part-Control Developer DEVEXPRESS newly announced its new data application tools for .NET's new data application tool Express Persistent Object v.1.5 for .NET, the code of its release is XPO, which is a specially used in .NET environment Database application development tool. DevexPress's development capabilities have been well known to the majority of programmers, based on the trust of the company's development tools, I think this control is not very big, but its development capability should be guaranteed. In its application process, there are some experience, not exclusive, now organize into text, for your reference to learn. Because of the limited level, it is inevitable, welcome to criticize and communicate. Can contact me Email. Express Persistent Objects for .NET provides a powerful bridge effect between the object's object and the relational database, which can provide developers with considerable degrees of freedom to create a real business object, without having to consider how to map it to Data tables are processed in the data sheet. Express Persistent Objects for .NET completely abstract the database layer from the developer's perspective, allowing developers to fully immerse in an object-oriented design atmosphere. By XPO, developers established applications can work well under various database systems (soon, will not support MsAccess and MSSQL database systems, don't you support it now? Oh, don't change a little code.

XPO is very easy to get started. If you have seen the example duwamish7 in Microsoft.visual.studio.Net.2003, in which the COMMON module will be blocked by the code segment mapped by its data sheet, but also feel that Microsoft's programmer will Is this machine? From its code, it has to be admitted that the subscriber programmer is indeed mechanical. However, if you have XPo, you will completely liberate from the machine's code. Developers need to do only to define a persistent object class, XPo.net automatically generates a database. XPO.NET will transparent (in the introduction of DevexPress, transparently "frequently appear, perhaps it is the highlights of the highlights), the relationship between the processing class and the object instance, does not have to sacrifice for flexibility Easy to use. If you want to control the O / R mapping relationship, you can use additional mapping information provided by XPO's built-in attribute to meet any business needs. Using XPo.net can directly develop database applications directly from the object model, do not have to spend more time in terms of table, column, relationship, and constraints, and put the main energy on the code, it makes you main The energy is concentrated on issues such as application requirements, and it is not necessary to have a headache for the bottleneck of the database. In short, it is the advantage of greatness, strong function, and a propaganda slogan for DevexPress is: Total Control, Flexibility and Power Bridging the Gap Between The Object World and rate Databases.XPO Example Figure 1, Express.Persistent.Object.v. 1.5 new features

Mapping the existing database. XPBaseObject is made as a base class to serve persistence objects. Support MSSQL7.0 (^ _ ^, this is also a new feature? Hehe). Page-level collector. The Pageselector class allows page management of a source container. The design period page management. The xppageselector component allows you to specify a page container as a data source and bind to the user interface in the design period. Container content is filtered. The XPCollection.filter property allows you to filter out existing container content and get a sub-container item that matches the filter criteria. The contents of the container are sorted and filtered. Non-persistent properties can be used to filter and sort the contents of the XPCollection container. Sort and filter options. XpCollection.casensensitive properties can control the case of the container member. New standard operation. AggRegateOperand allows operations to operate via aggregate.sum, aggregate.count, aggregate.min, and aggregate.max action options. Support value object. Value and type conversion. Bid-way conversions between database values ​​and persistence properties are implemented with the ValueConvertRibute class. Map of database view. Persistent objects can now be mapped to the database view. Persistent null value. Null values ​​can be stored in the database via NullValueAttribute. Customize the database type. With a persistence attribute or field mapping, DBTYPEATTRIBUT can be used to identify the type of column. Track the content of the container content. You can track changes in container content via CollectionChanged events. Performance improvement. When the object is loaded, ExPlicitLoadingAttribute helps optimize database query performance. XpBaseObject. XPBaseObject is now supported IedITableObject. You can control the change in the object by this interface. XpBaseObject. XPBaseObject is now a virtual instthconstruction method that allows logic to create an autonomous object. XpCollection. XPCOLLECTION Extension CollectionChanged events provide custom actions during the container operation. 2, XPO how to work-oriented application design and development provides current complex application development to provide high-performance and multi-production means, improved code reuse, and higher flexibility when end user needs . When creating a database app, developers seem to be forced to deal with data sheets, views, data field objects, rather than direct processing of business objects. This gap in this relational database object is similar to the difference in commercial objects in ADO.NET and specific areas, which is the same for developers. Visual Studio .NET tries to solve this problem by type security data set: a developer can pick a data table and generate a type of secure data set, so that the class looks more similar to business objects in a transaction domain, this The mechanism is used to achieve persistent business objects, although it seems that such objects are more like a structure. So no way can map your design a good business object model to a relational database without having to handle the data table and field? Maybe you have guess this answer. This is necessary to achieve such work through XPO. XPO is trying to solve this problem from another different angle - through the perspective of the world of business objects. Look at a small example. In a sales management application, a contact with a contact is represented by:

Public las contact {public string firstname; public string limited, public string email;} Obviously, all contacts in the sales management application should be saved in the database, so Contact is inevitably a persistent object. If you want to last, it is very simple, but you need to do it from XPObject: use meansXpress.xpo; ... public class contact: xpobject {public string firstname; public string Lastname; Public String Phonenumber Public String email;} Generally, you must specify a joint string to connect to the database before using the persistent object, similar to the following code:

... session.defaults = "..."; Contact Contact = new contact (); contact.firstname = "john"; contact.lastname = "doe"; contact.email = "jdoe@johndoe.com" Contact.save (); ... through the above simple code, create a Contact table in the .NET environment and insert a record to the inside. So how do you use this object from your database? XPO.NET provides XPCOLLECTION to use objects:

XPCollection contacts = new XPCollection (typeof (Contact)); foreach (Contact contact in contacts) {Console.WriteLine (contact.Email);} comparison Fortunately, XPCollection DataGrid as data sources to display in list DataGrid among Contect :

ContactDataGrid.dataSource = Contacts; if you want to change the display object in DataGrid, you can set up the Contact.DisplayAbleProperties:

Contacts.displayableProperties = "firstname; lastname; email"; Most of the time, do not need to take all Contact objects from the database, and the actual situation is often found in a certain standard to find some objects, the database management system often provides SQL query Complete such tasks, it can be used instead of the foreach stack:

XpCollection JDOE = New XpCollection (TypeOf (Contact), New GroupOperator ("Firstname", New BinaryOperator ("Lastname", "DOE"))); John DOE object, similar to SQL query statement in the database. By default, the objects in the container are disorderly, and the following code takes the firstname = "john" and the lastName is sorted in ascending order.

XpCollection JDOE = New XPCOLLECTION (TypeOf (Contact), New BinaryOperator ("Firstname", "John"), New Sortproperty ("Lastname", sortingdirection.ascending); In most commercial models, data sheets do not exist independently Most of the tables and tables have such a relationship. For example, contacts often belong to a company: use meansXpress.XPO; ... public class company: XpObject {public string name; public string phoneenumber; public string WebSite;} public class Contact: XPObject {public string FirstName; public string LastName; public string PhoneNumber; public string Email; public Company Employer;} case there is a relationship in the data table, XPO.NET know property is another commercial Employer The object's reference, thus automatically maintaining the existence of this relationship in the database structure, and no handcodes are required. If a business object has a child object, for example, a certain order fine will have a certain order in a normal order. Item, I need to give XPo.net a small "prompt" telling that the child object will be stored in the container:

using DevExpress.Xpo; ... public class OrderLine: XPObject {public string Description; public double Price; public int Quantity; [Association ( "OrderLines")] public Order Order;} public class Order: XPObject {public string OrderNo; public String Description; [AGGREGATED] [Association ("ORDERLINES")] Public XpCollection OrderLines {Get {Return getCollection ("ORDERLINES");}}} The object variable allows us to be referenced in the program, but it is not This is the only existence, so it is necessary to identify the object in the program operation process. There is an OID attribute in each persistent object, the OID identifies a unique identifier of a specified class:

转载请注明原文地址:https://www.9cbs.com/read-12459.html

New Post(0)