Object link ing
Agileeas. netorm does not adopt the file ing mode, such as nhib.pdf, but uses the direct hard-coding mode, the ORM system design adopts the structure of attribute/column> Data Object> data set (table:
The most basic idea is to map a record/entity (ientity) to a record. An object includes several attributes/columns (colunm ), A group of ientity and a group of colunm form a data table object (ientity), which is used for an object, a table, a view, or a query result. The following describes the classes and interfaces involved:
Column
It is equivalent to a column in a database table. It is organized in the row of the database and database table and consists of 1-n columns to form a row of data or a database table, includes attributes such as title, name, data type, database column name, size, value expression, auto-increment, value, and default value. These attributes are convenient for you to use when defining database entity classes and table classes. In database attribute classes, an attribute is typically equivalent to a number of database columns. However, an attribute may not be associated with a database column, but can also be associated with a function or constant.
Ientity
An object interface is related to a database table row in a relational database, and maps a database table row to a database record.
Database entity interfaces and data table interfaces are the core interfaces in Orm. Why is they the core interfaces? They are the data entity objects in Orm ing) directly ing relationships (tables) with relational databases. A database table row has only one element (that is, a table with only one record) the data table is a vertical row extension of the database table row. The database entity interface implements the set of attributes required for row ing with the database table. It also provides refresh, insert, update, save, and delete database persistence operations and a cacherefresh method.
The refresh method is a method for synchronizing data object from the row of the relational database table. It extracts the specified row data from the relational database table and synchronizes the internal data Implementation object.
The Save method is a method for synchronizing a data object to a relational database table. If this row exists in a database table, modify the row in the database table, if this row does not exist in the row of the database table, insert this row into the database table.
The insert method inserts data directly into the database without interpretation.
The update method directly updates database records without interpretation.
The delete method deletes the row of Data mapped to the data object from the relational database.
The cacherefresh method is the same as the refresh method, but not from the database but from the cache.
Itable
A data table is related to a database table in a relational database and maps a database table to a data table. In itable, we define columns and rows, it also provides query, save, and delete database persistence operations and cache query cachequery.
The query method is a method for synchronizing data table objects from relational database tables. It extracts the specified row of data from relational database tables and synchronizes the data table objects in the memory.
During the execution of the query method, you can synchronize all the database table data at a time, or synchronize some data of the database according to the condition, the query condition object (condition), query condition Element Object (element), and result sorting Element Object (ordeelement) need to be used to combine these three objects into complex query conditions, query the data of a specified condition using the query method.
The implementation of the SAVE and delete methods is similar to that in the ientity definition.
Cachequery synchronizes data rows from the cache.
In the object architecture of the above Orm, there are two collection classes entitycollection and columncollection which are not described here. For details, refer to the class library help in the Development Kit. Below I will talk about the query CONDITIONS IN THE ORM.
We know that condition query is required for database operations. We map rows, columns, and tables to objects. What should we do with SQL conditions? agileeas. net defines three classes: Query condition, element, and sorting condition.
Condition
The condition class is a function auxiliary class in Orm, which is equivalent to a set of query conditions compiled by developers During the Process of numbering SQL statements. Conditions are composed of Condition Unit components. If conditions are used for query, you need to sort the query results. You just need to use the sorting Condition Unit. The following is the structure relationship between the condition class and Condition Unit:
Is the class relationship between conditions, element, and ordeelement. The condition element () is associated with the Condition Unit and the sorting unit by the method, and Element) it indicates a very simple condition element, such as name = 'James '. The ordeelement only indicates a very simple sorting unit, such as name or name DESC, however, in our enterprise application development, the conditions are very complex, for example, the condition name = 'James 'and sex = 'male' and age <16, in this case, we use condition units to form complex conditions. In this condition, we use ORM for ing:
Condition condition = table. createcondition ();
Condition. addelement (new element ("name", "James ");
Condition. addelement (new element ("sex", "male ");
Condition. addelement (new element ("Age", "16 ");
In this way, we have completed the definition of this condition. In the process of combination of conditions and defining conditions, we have an understanding that the conditions are not simply equivalent comparisons, there are also many other condition types. Likewise, condition combinations are not only combination of and or, but also two secondary enumeration types in Orm condition ing, listing condition types and condition combination types.
Elementtype
Condition Type enumeration defines the type of a condition, such as =, <, like, and so on:
Elementtype /// <Summary> /// Data Element (element) type enumeration of the condition class. /// </Summary> Public Enum Elementtype {/// <Summary> /// "=" Compares the specified value with the specified attribute /// </Summary> Failed to = 0x00000000, /// <Summary> /// ">" Compares the specified value with the specified attribute /// </Summary> Greaterthan = 0x00000001, /// <Summary> /// "> =" Compares the specified value with the specified attribute /// </Summary> Greaterthandequalto = 0x00000002, /// <Summary> /// Compare the specified value with the specified attribute /// </Summary> Notequalto = 0x00000003,/// <Summary> /// Compare the specified value with the specified attribute /// </Summary> Lessthan = 0x00000004, /// <Summary> /// Compare the specified value with the specified attribute /// </Summary> Lessthanandequalto = 0x00000005, /// <Summary> /// (Between), which is between two threads. /// </Summary> Between = 0x00000010, /// <Summary> /// (Notbetween), which is not in the range of two parameters. /// </Summary> Notbetween = 0x00000020,/// <Summary> /// Match the specified sub-string (pattern matching % value %) /// </Summary> Match = 0x00000100, /// <Summary> /// Match the specified sub-string (prefix matching Value %) /// </Summary> Matchprefix = 0x00000200, /// <Summary> /// Match the specified sub-string (suffix matching % value) /// </Summary> Matchsuffix = 0x00000300, /// <Summary> /// The specified sub-string does not match (% value % ). /// </Summary> Notmatch = 0x00000400, /// <Summary> /// The specified sub-string does not match the specified owner (the prefix does not match value % ). /// </Summary> Notmatchprefix = 0x00000500, /// <Summary> /// The specified sub-string does not match the specified owner (the suffix does not match % value ). /// </Summary> Notmatchsuffix = 0x00000600, /// <Summary> /// Match the characters in the sub-string (the word matches value _ value ). /// </Summary> Wordmatch = 0x00000700, /// <Summary> /// The characters in the substring do not match (the words match value _ value ). /// </Summary> Notwordmatch = 0x00000800, /// <Summary> /// Match the value in the given list. /// </Summary> In = 0x00001000, /// <Summary> /// It does not match the value in the given list. /// </Summary> Notin = 0x00002000, /// <Summary> /// Directly construct a string. input is a condition element. /// </Summary> Sqlcondition = 0x00008000}
In these definitions, there is a special condition type, sqlcondition condition type. When we map conditions, the actual data is always complex, and many cannot be mapped directly using various conditions, alternatively, the single-condition ing component has complex conditions. We can directly use SQL statements as conditions. At this time, we can use the sqlcondition condition type. It retains the interface for writing high-quality and efficient SQL language names.
Elementcombinetype
Combination of two conditions or two condition elements, or and
/// <Summary>/// A combination of elements in the condition class./// </Summary>Public EnumElementcombinetype {/// <Summary>/// And, two element objects are combined with and./// </Summary>And = 0x0000,/// <Summary>/// Or, two element objects are combined with or./// </Summary>OR = 0x0001}
Interface-Driven Data Layer
Agileeas. NET platform has been practicing the idea of interface-driven, and it is also recommended that application development based on interface-driven, agileeas. NET platform implements a set of practical and simple Orm. The data access layer for application development is also the data access layer based on ORM technology.
During application development, we often encounter the same product needs to run on different database systems, compared with other versions that require running on sqlserver and those that require running on oraclr.
In this case, the interface-Driven Data access layer is a good choice; define a set of data access layer interface components and the data access layer implementation components of different database types, business implementation depends on the data interface layer and is decoupled from the data Implementation Layer. You only need to modify the system configuration file for different database types during runtime.
Let me list an example. I also provide an example of data access. We define an example named EAS. exam. dal. interface Class Library Project, including iiteminfo (Service Project), iiteminfolist (Service Project table), iproduct (product), iproductlist (product table) Four entity interfaces, an idalmanager interface is used to manage the four types of concrete instance libraries. It is used to instantiate objects. See the definition below:
Public interface idalmanager
{
Iiteminfo createiteminfo ();
Iiteminfolist createiteminfolist ();
Iproduct createproduct ();
Iproductlist createproductlist ();
}
In the EAS. Exam. Dal. interface project, we define a dalhelper class:
Public class dalhelper
{
Static string componentkey = "EAS. Exam. Dal ";
Public static idalmanager dalmanager
{
Get
{
Return contexthelper. getcontext (). Container. getcomponentinstance (componentkey) as idalmanager;
}
}
}
The dalhelper class is a helper class that provides a static attribute of the dalmanager name and returns a specific instantiated idalmanager object. It may be the implementation of sqlserver or Oracle.
We define a project EAS. Exam. Dal. sqlserver to implement these four physical interfaces and dalmanager interfaces respectively:
Class dalmanager: idalmanager
{
# Region idalmanager Member
Public iiteminfo createiteminfo ()
{
Return new iteminfo ();
}
Public iiteminfolist createiteminfolist ()
{
Return new iteminfolist ();
}
Public iproduct createproduct ()
{
Return New Product ();
}
Public iproductlist createproductlist ()
{
Return new productlist ();
}
# Endregion
}
For implementation of Oracle Database EAS. Exam. Dal. sqlserver, refer to sqlserver implementation.
In the system configuration file (IOC) configuration section, add an object definition named EAS. Exam. Dal. The Assembly and type are configured according to the required data access layer.
Sqlserver data access layer:
<Object name = "EAS. Exam. Dal" lifestyletype = "Singleton"
Assembly = "EAS. Exam. Dal. sqlserver" type = "EAS. Exam. Dal. sqlserver. dalmanager"/>
Oracle Data access layer:
<Object name = "EAS. Exam. Dal" lifestyletype = "Singleton"
Assembly = "EAS. Exam. Dal. Oracle" type = "EAS. Exam. Dal. Oracle. dalmanager"/>
In the interface-Driven Data access layer, IOC container decoupling is used in the preceding example. We recommend that you use this mode for application development.ProgramMember research uses new projects, such as image profiling methods.
Tool support
In application development, you can select the data layer for manual encoding.CodeYou can also use the data object designer provided by the agileeas. NET platform to generate orm and interface-driven hierarchical code implementation.
On the agileeas. NET platform, we provide a data Entity Designer that integrates database design, code generation, DDL definition, and so on:
In the early stages of agileeas. the Net version contains a code generator used to generate ORM code based on the current database. Later, the idea was to intervene in the database design stage of the project. Therefore, such a data object designer was designed, provides a data table definition tool to define both the database and data entity model at the database design stage (stage) of the project.
After the model is defined, you can directly survive the database design document and the database definition language DDL (data can generate Oracle and sqlserver databases ).
As well as the ORM code based on the Division class and the interface-driven Dal solution and project, we need to explain that one problem is the division class. In application development, our operations on the database are not only simple operations such as reading, updating, adding, and deleting, but also complicated database processing that works with the business logic in the Dal layer, this requires the programmer to modify the generated code, which raises a problem. When we modify the data definition module and use the tool to regenerate the code, the original operation will be overwritten, to solve this problem, agileeas. NET introduces the technology of Division class to break down the implementation of an object or table object into two parts, namely, the module-related definition part and the business-related part. At the first generation, the survivability generates written definitions and an empty business code file. The programmer adds the business processing code to the Business Code file, when the model is modified and re-generated, only the code files related to the model definition are overwritten.
In addition, the data object designer provides a reverse generation tool based on the current database generation model. Currently, it supports Oracle and sqlserver databases.
Recommended Practices
Currently, most small and medium-sized software enterprises are engaged in the development of database-related information systems. 80-90% of the businesses in the project are related to databases, it is also a typical data-driven development.
Agileeas. NET platform provides a series of support and practices for large-scale data interaction applications, from database design to code generation and Business Code extension.
Define Data Object Model
After the application system or word system needs to enter the design stage, agileeas. NET provides data object design tools to complete database design and data object definition in two steps. Using Data design and definition tools, independent database design steps are no longer required in the project design phase, the data object definition tool outputs the Data Definition Language DDL and database design documents.
After the data object model is designed, it can be saved as the extension. the data definition model file of SDM synchronizes the definition of the database (Table Name, column name, data number type, length, decimal number, and whether it is not empty) during the definition of the data model), Orm object definition (entity name, attribute name, type, title), and the relationship between database tables and ORM entities (column name ---> attribute name ).
With metadata definitions of database tables, we can generate database design documents and database definition language DDL. With the metadata definition of ORM entities, we can generate ORM entity code in the editing stage, in fact, the code generator generates the data access layer code based on the interface driver layer.
You can select the project name, title,Programming Language(C #, VB), namespace, output directory, and other information required for code generation, as shown in the figure below:
And the database types and connection information required for DDL generation and model generation from the database:
Generate database documents
The Data Object designer provided by agileeas. Net can generate database documents based on the designed data object model. The document format is as follows:
Generate database scripts
The Data Object designer can generate scripts for innovative database tables based on the designed data object model. The scripts contain descriptive information for creating tables, primary keys, tables, and fields, directory can generate DDL scripts for sqlserver and Oracle databases.
Generate data access layer code
The data access layer code is generated based on the data object model designed during the database design stage. The generated code includes a data access interface project and a database type data access layer implementation set during model design.
The interface-Driven Data access layer code generated by the ORM object designer adopts the distribution technology, that is, the same implementation interface or implementation is decomposed into two or more files, in this way, the generator pre-sets the basic definition information associated with the object and the database in a file, with more file names. generator character, which is put in a file related to the business, in the same project ,. the generator file is placed in a separate folder generat, and it is recommended that developers do not make task changes to this file.
For business expansion data layer code that has a certain correlation with specific businesses and is not simply afraid of crud operations, developers can write it without it. generator character file to ensure that business-related program code is not overwritten after the code is regenerated.
Link
Agileeas. NET platform development guide-series Directories
Introduction to agileeas. NET application development platform-Index
Official website of agileeas. net
Agile Software Engineering Lab
QQ: 116773358