CN104731911A - Dynamic mapping and conversion method of data table and entity class - Google Patents

Dynamic mapping and conversion method of data table and entity class Download PDF

Info

Publication number
CN104731911A
CN104731911A CN201510129831.3A CN201510129831A CN104731911A CN 104731911 A CN104731911 A CN 104731911A CN 201510129831 A CN201510129831 A CN 201510129831A CN 104731911 A CN104731911 A CN 104731911A
Authority
CN
China
Prior art keywords
title
row
source
destination object
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201510129831.3A
Other languages
Chinese (zh)
Inventor
田尚杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Group Co Ltd
Original Assignee
Inspur Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Group Co Ltd filed Critical Inspur Group Co Ltd
Priority to CN201510129831.3A priority Critical patent/CN104731911A/en
Publication of CN104731911A publication Critical patent/CN104731911A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/288Entity relationship models

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a dynamic mapping and conversion method of a data table and an entity class. The method comprises the following steps that a mapping relation description character string between a source data object Data Table and a target data object entity is constructed, data extraction is performed on the source data object Data Table, and data extracted from a source data object are converted into the target data object entity. Compared with the prior art, the dynamic mapping and conversion method of the data table and the entity class achieves rapid capture of various data in a database, achieves modeled displaying of the various data, is high in practicability and is easy to popularize.

Description

The dynamic mapping of a kind of tables of data and entity class and conversion method
Technical field
The present invention relates to technical field of data processing, specifically the dynamic mapping of a kind of practical, tables of data and entity class and conversion method.
Background technology
Object Relation Mapping (Object Relational Mapping, is called for short ORM, or O/RM, or O/R mapping) is a kind of program technic, for realize dissimilar system in Object-Oriented Programming Language data between conversion.General needs build source object type and destination object type in advance, and destination object type must be strongly-typed or hard coded, and source object type and destination object type all will have the Schema of a more complicated to describe.
LINQ is the abbreviation of Language Integrated Query, and it is a kind of characteristic be integrated in .NET programming language.Become an ingredient of programming language, syntax check when can well be compiled when coding, abundant metadata, the benefit of the strongly typed language such as Intellisense, static types.
In actual development process, our " service logic " usually needs us to carry out various conversion to same data.Such as, a Web application becomes data connection object (DTO) by the input of front end collection user, then converts DTO to domain model and is persisted in database.On the other hand, when user's request msg, we need again to do contrary work: convert the domain model checked out from database to DTO in the opposite manner and present to user again.
Often be converted to a kind of entity type, all need hand-coding transcode, waste time and energy.
Based on this, now provide a kind of tables of data of describing based on character string and the dynamic mapping of entity class and conversion method, the method utilizes the characteristic of LINQ, realizes the scheme of Object Relation Mapping and conversion between DTO and database table.
Summary of the invention
Technical assignment of the present invention is for above weak point, provides dynamic mapping and the conversion method of a kind of practical, tables of data and entity class.
The dynamic mapping of tables of data and entity class and a conversion method, its specific implementation process is:
One, the mapping relations building source data object DataTable and target data objects inter-entity describe character string;
Two, data pick-up is carried out from source data object DataTable;
Three, the data extracted from source data object are converted to target data objects entity.
Character string type is used to describe the basic syntax of mapping relations in described step one as follows:
Fr [" source object row 1 title "] to destination object attribute 1 title, Fr [" source object row 2 title "] to destination object attribute 2 title ..., Fr [" source object row n title "] to destination object attribute n title;
Wherein, Fr [" source object row 1 title "] to destination object attribute 1 title, represents the attribute a certain row of source object being mapped to destination object; Fr and to is fixed keyword; Source object row 1 title, source object row 2 title, source object row n title, represent the row title of a certain row of source object; Destination object attribute 1 title, destination object attribute 2 title, destination object attribute n title are Property Names of destination object.
The specific descriptions grammer of described mapping relations is:
(Fr [" source object row m title "] operational symbol Fr [" source object row n title "]) to destination object Property Name;
Wherein, operational symbol comprises "+", "-", " * ", "/" four kinds, the value of object before and after operational symbol row be integer and value type time, use any one in above four kinds of operational symbols; When the value of the object row before and after operational symbol is character types, use "+" operational symbol.
Perform mapping between source data object and target data objects and when changing, first mapping relations will be described character string and be converted to the Lambda expression formula meeting Linq and require, namely system converts a Lambda expression formula fragment to each Fr [" source object row title "] the to destination object Property Name that mapping relations describe in character string:
According to the type of the destination object entity imported into, dynamic construction destination object entity class; When the type of the destination object entity imported into is null, then the entity class of a dynamic construction dynamic type;
When running into keyword Fr, system, according to [" source object row n title "] thereafter, corresponds to row name it and calls in the data of " source object row n title ", and as the left section of current Lambda expression formula fragment;
When running into keyword to, system is according to " destination object Property Name " thereafter, the attribute in destination object entity representated by " destination object Property Name " is obtained by the mode of reflection, and using the right section of this attribute as current Lambda expression formula fragment;
The type of the destination object attribute of system representated by the right section of Lambda expression formula fragment, after the value of the source object row representated by the left section of Lambda expression formula fragment is carried out type conversion, assignment is to the destination object attribute representated by the right section of Lambda expression formula fragment.
The dynamic mapping of a kind of tables of data of the present invention and entity class and conversion method, have the following advantages:
The dynamic mapping of a kind of tables of data that the present invention proposes and entity class and conversion method, can at any time by the character string of a specific format, describe the mapping relations of source object and destination object inter-entity, and obtain the object entity of needs fast, without the need to carrying out complicated coding; Utilize this feature, can the quick crawl of various data in fulfillment database, and the object entity be converted to required for displaying, be particularly suitable for as the VierwModel layer object entity in MVC provides data, when View determines, by different configurations, the medelling that can realize various data represents, practical, be easy to promote.
Accompanying drawing explanation
Accompanying drawing 1 is mapping of the present invention and transfer process schematic diagram.
Embodiment
Below in conjunction with the drawings and specific embodiments, the invention will be further described.
The invention discloses dynamic mapping and the conversion method of a kind of tables of data and entity class, as shown in Figure 1, its specific implementation process is:
One, the mapping relations building source data object DataTable and target data objects inter-entity describe character string;
Two, data pick-up is carried out from source data object DataTable;
Three, the data extracted from source data object are converted to target data objects entity.
Use the mapping relations of character string type to describe the mapping relations described between source data object and target data objects, it is as follows that its mapping relations describe basic syntax:
Fr [" source object row 1 title "] to destination object attribute 1 title, Fr [" source object row 2 title "] to destination object attribute 2 title ..., Fr [" source object row n title "] to destination object attribute n title.
Wherein, Fr [" source object row 1 title "] to destination object attribute 1 title, represents the attribute a certain row of source object being mapped to destination object; Fr and to is fixed keyword; Source object row 1 title, source object row 2 title, source object row n title, represent the row title of a certain row of source object, determine according to source object, non-ly refers in particular to a certain row; Destination object attribute 1 title, destination object attribute 2 title, destination object attribute n title are Property Names of destination object, determine according to destination object, non-ly refer in particular to.
The specific descriptions grammer of described mapping relations is:
(Fr [" source object row m title "] operational symbol Fr [" source object row n title "]) to destination object Property Name;
Wherein, operational symbol comprises "+", "-", " * ", "/" four kinds, the value of object before and after operational symbol row be integer and value type time, use any one in above four kinds of operational symbols; When the value of the object row before and after operational symbol is character types, use "+" operational symbol.
When performing the mapping between object and change, first mapping relations to be described character string and be converted to the Lambda expression formula meeting Linq and require.
Mapping relations describe character string be converted to meet Linq require Lambda expression formula time, according to the type of the destination object entity imported into, dynamic construction destination object entity class; If the type of the destination object entity imported into is null, then the entity class of a dynamic construction dynamic type.
Mapping relations describe character string be converted to meet Linq require Lambda expression formula time, system can convert a Lambda expression formula fragment to each Fr [" source object row title "] the to destination object Property Name that mapping relations describe in character string.
Mapping relations describe character string be converted to meet Linq require Lambda expression formula time, when running into keyword Fr, the system realizing this method can according to [" source object row n title "] thereafter, it is corresponded to row name calls in the data of " source object row n title ", and as the left section of current Lambda expression formula fragment.
Mapping relations describe character string be converted to meet Linq require Lambda expression formula time, when running into keyword to, the system realizing this method can according to " destination object Property Name " thereafter, the attribute in destination object entity representated by " destination object Property Name " is obtained by the mode of reflection, and using the right section of this attribute as current Lambda expression formula fragment.
Mapping relations describe character string be converted to meet Linq require Lambda expression formula time, system can the type of destination object attribute representated by the right section of Lambda expression formula fragment, after the value of the source object row representated by the left section of Lambda expression formula fragment is carried out type conversion, assignment is to the destination object attribute representated by the right section of Lambda expression formula fragment.
In above-mentioned steps, step 2 carries out the realization of data pick-up, provide firstly an interface, and destination object type, mapping relations are described character string and import into, and its entry method realizes as follows:
public static IQueryable<TResult> Select<TResult>(this IQueryable source, string selector, params object[] values)
{
if (source == null) throw new ArgumentNullException("source");
if (selector == null) throw new ArgumentNullException("selector");
LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(TResult), selector, values);
return source.Provider.CreateQuery<TResult>(
Expression.Call(
typeof(Queryable), "Select",
new Type[] { source.ElementType, typeof(TResult) },
source.Expression, Expression.Quote(lambda)));
}
Wherein, TResult is destination object type, if the type do not determined, can import Object into, system will be mapped as dynamic type; Selector is that the mapping relations imported into describe character string.
Next system, by analyzing the mapping relations imported into, character string is described, take space as analysis foundation, find out each key word wherein, and then be converted to list formula, finally by the function of Linq, executable expressions is set, and DataTable is converted to destination object entity, is wherein converted to destination object entity key code as follows:
Type type = newResultType DynamicExpression.CreateClass(properties);
MemberBinding[] bindings = new MemberBinding[properties.Count];
for (int i = 0; i < bindings.Length; i++)
bindings[i] = Expression.Bind(type.GetProperty(properties[i].Name), expressions[i]);
return Expression.MemberInit(Expression.New(type), bindings)。
Wherein newResultType is destination object entity type.
Embodiment: final realization of the present invention is the DLL under a .NET environment, in use, has the following steps:
The first step: first quote this DLL in code engineering, and NameSpace INSPUR.Dynamic.AutoMap is added in relevant class;
Second step: in suitable code position, according to order object type and source object type, builds string table single entry, as:
Fr["LastName "] to UserName, Fr["EmployeeID "] to UserID
3rd step: call method Select<TResult>, as:
var users = dt.AsEnumerable()
.AsQueryable()
.Select<User>("Fr[\"LastName\"] to UserName,
Fr [\"EmployeeID\"] to UserID");
Above in code, dt is source object tables of data DataTable, User is destination object entity class, " Fr [" LastName "] to UserName; Fr [" EmployeeID "] to UserID " is character string maps relational expression, have double quotation marks due to inside and outside, therefore escape process has been done in inside.
By above three steps, just complete tables of data to the mapping of object entity and conversion, convenient and swift.
Above-mentioned embodiment is only concrete case of the present invention; scope of patent protection of the present invention includes but not limited to above-mentioned embodiment; any a kind of tables of data according to the invention and the dynamic mapping of entity class and claims of conversion method and the those of ordinary skill of any described technical field to its suitable change done or replacement, all should fall into scope of patent protection of the present invention.

Claims (4)

1. the dynamic mapping of tables of data and entity class and a conversion method, it is characterized in that, its specific implementation process is:
One, the mapping relations building source data object DataTable and target data objects inter-entity describe character string;
Two, data pick-up is carried out from source data object DataTable;
Three, the data extracted from source data object are converted to target data objects entity.
2. the dynamic mapping of a kind of tables of data according to claim 1 and entity class and conversion method, is characterized in that, uses character string type to describe the basic syntax of mapping relations as follows in described step one:
Fr [" source object row 1 title "] to destination object attribute 1 title, Fr [" source object row 2 title "] to destination object attribute 2 title ..., Fr [" source object row n title "] to destination object attribute n title;
Wherein, Fr [" source object row 1 title "] to destination object attribute 1 title, represents the attribute a certain row of source object being mapped to destination object; Fr and to is fixed keyword; Source object row 1 title, source object row 2 title, source object row n title, represent the row title of a certain row of source object; Destination object attribute 1 title, destination object attribute 2 title, destination object attribute n title are Property Names of destination object.
3. the dynamic mapping of a kind of tables of data according to claim 2 and entity class and conversion method, it is characterized in that, the specific descriptions grammer of described mapping relations is:
(Fr [" source object row m title "] operational symbol Fr [" source object row n title "]) to destination object Property Name;
Wherein, operational symbol comprises "+", "-", " * ", "/" four kinds, the value of object before and after operational symbol row be integer and value type time, use any one in above four kinds of operational symbols; When the value of the object row before and after operational symbol is character types, use "+" operational symbol.
4. according to dynamic mapping and the conversion method of the arbitrary described a kind of tables of data of claim 1-3 and entity class, it is characterized in that, perform mapping between source data object and target data objects and when changing, first mapping relations will be described character string and be converted to the Lambda expression formula meeting Linq and require, namely system converts a Lambda expression formula fragment to each Fr [" source object row title "] the to destination object Property Name that mapping relations describe in character string:
According to the type of the destination object entity imported into, dynamic construction destination object entity class; When the type of the destination object entity imported into is null, then the entity class of a dynamic construction dynamic type;
When running into keyword Fr, system, according to [" source object row n title "] thereafter, corresponds to row name it and calls in the data of " source object row n title ", and as the left section of current Lambda expression formula fragment;
When running into keyword to, system is according to " destination object Property Name " thereafter, the attribute in destination object entity representated by " destination object Property Name " is obtained by the mode of reflection, and using the right section of this attribute as current Lambda expression formula fragment;
The type of the destination object attribute of system representated by the right section of Lambda expression formula fragment, after the value of the source object row representated by the left section of Lambda expression formula fragment is carried out type conversion, assignment is to the destination object attribute representated by the right section of Lambda expression formula fragment.
CN201510129831.3A 2015-03-24 2015-03-24 Dynamic mapping and conversion method of data table and entity class Pending CN104731911A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510129831.3A CN104731911A (en) 2015-03-24 2015-03-24 Dynamic mapping and conversion method of data table and entity class

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510129831.3A CN104731911A (en) 2015-03-24 2015-03-24 Dynamic mapping and conversion method of data table and entity class

Publications (1)

Publication Number Publication Date
CN104731911A true CN104731911A (en) 2015-06-24

Family

ID=53455798

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510129831.3A Pending CN104731911A (en) 2015-03-24 2015-03-24 Dynamic mapping and conversion method of data table and entity class

Country Status (1)

Country Link
CN (1) CN104731911A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105550242A (en) * 2015-12-08 2016-05-04 方正移动传媒技术(北京)有限公司 Data processing method and device of relational database
CN106843872A (en) * 2017-01-17 2017-06-13 千寻位置网络有限公司 Assignment conversion method
CN106933554A (en) * 2015-12-30 2017-07-07 北京国双科技有限公司 Class conversion method and device
CN106951427A (en) * 2016-01-07 2017-07-14 阿里巴巴集团控股有限公司 A kind of data pick-up method and device of business object
CN108153655A (en) * 2017-12-18 2018-06-12 福建天晴数码有限公司 The detection method and storage medium of the draw call quantity of virtual reality software
CN109901822A (en) * 2019-01-08 2019-06-18 平安科技(深圳)有限公司 The mutual shifting method of object, device and storage medium, server
CN113110847A (en) * 2021-04-29 2021-07-13 杭州以诺行汽车科技股份有限公司 Program code conversion processing method and system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050050068A1 (en) * 2003-08-29 2005-03-03 Alexander Vaschillo Mapping architecture for arbitrary data models
CN1647080A (en) * 2002-04-25 2005-07-27 国际商业机器公司 A method, computer program and computer for accessing data in an environment of multiple data repositories
CN101008952A (en) * 2007-01-30 2007-08-01 华为技术有限公司 Method and device for generating persistence layer
CN101405729A (en) * 2006-03-23 2009-04-08 微软公司 Mapping architecture with incremental view maintenance

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1647080A (en) * 2002-04-25 2005-07-27 国际商业机器公司 A method, computer program and computer for accessing data in an environment of multiple data repositories
US20050050068A1 (en) * 2003-08-29 2005-03-03 Alexander Vaschillo Mapping architecture for arbitrary data models
CN101405729A (en) * 2006-03-23 2009-04-08 微软公司 Mapping architecture with incremental view maintenance
CN101008952A (en) * 2007-01-30 2007-08-01 华为技术有限公司 Method and device for generating persistence layer

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
夏树立: "《基于对象关系映射技术的数据持久层的研究与应用》", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *
王振杰: "《基于LINQ的B_S开发架构的设计与应用》", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *
蒋冠雄 等: "《一种支持模糊查询的LINQ动态查询方案》", 《计算机时代》 *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105550242A (en) * 2015-12-08 2016-05-04 方正移动传媒技术(北京)有限公司 Data processing method and device of relational database
CN106933554A (en) * 2015-12-30 2017-07-07 北京国双科技有限公司 Class conversion method and device
CN106951427A (en) * 2016-01-07 2017-07-14 阿里巴巴集团控股有限公司 A kind of data pick-up method and device of business object
CN106951427B (en) * 2016-01-07 2020-08-18 阿里巴巴集团控股有限公司 Data extraction method and device for business object
CN106843872A (en) * 2017-01-17 2017-06-13 千寻位置网络有限公司 Assignment conversion method
CN108153655A (en) * 2017-12-18 2018-06-12 福建天晴数码有限公司 The detection method and storage medium of the draw call quantity of virtual reality software
CN109901822A (en) * 2019-01-08 2019-06-18 平安科技(深圳)有限公司 The mutual shifting method of object, device and storage medium, server
WO2020143306A1 (en) * 2019-01-08 2020-07-16 平安科技(深圳)有限公司 Object inter-conversion method and apparatus, storage medium, and server
CN113110847A (en) * 2021-04-29 2021-07-13 杭州以诺行汽车科技股份有限公司 Program code conversion processing method and system
CN113110847B (en) * 2021-04-29 2024-02-13 杭州以诺行汽车科技股份有限公司 Conversion processing method and system for program codes

Similar Documents

Publication Publication Date Title
CN104731911A (en) Dynamic mapping and conversion method of data table and entity class
CN108052321B (en) Method for automatically generating intelligent contract of block chain based on configuration information
Astrova et al. Storing OWL ontologies in SQL relational databases
AU2004237062B2 (en) Retaining hierarchical information in mapping between XML documents and relational data
Patel-Schneider Analyzing schema. org
CN104866593A (en) Database searching method based on knowledge graph
US8983931B2 (en) Index-based evaluation of path-based queries
CN106407201A (en) Data processing method and apparatus
Raffio et al. Clip: a visual language for explicit schema mappings
CN102999563A (en) Network resource semantic retrieval method and system based on resource description framework
CN101841515A (en) Target variable protocol data unit codec code automatic generation implementation method
CN104601554B (en) A kind of method for interchanging data and DEU data exchange unit
US20060161525A1 (en) Method and system for supporting structured aggregation operations on semi-structured data
Čerāns et al. Rdb2owl: A RDB-to-RDF/OWL mapping specification language
CN103678396B (en) A kind of data back up method and device based on data model
CN103020318A (en) Method for maintenance of database tables in database
CA3144686A1 (en) Sql statement generator
CN103902651B (en) Cloud code query method and device based on MongoDB
KR20130064160A (en) System of entity-relationship model reformulation of sparql query results on rdf data and the method
CN105550176A (en) Basic mapping method for relational database and XML
CN102043802B (en) Method for searching XML (Extensive Makeup Language) key words based on structural abstract
Shen et al. A graph-based RDF triple store
Fisher et al. Use of OWL and SWRL for Semantic Relational Database Translation.
Ling et al. Translating relational databases into RDF
Alaoui et al. Automatic Mapping of Relational Databases to OWL Antology

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20150624