VCL ExpressEntityMapping Framework
- 5 minutes to read
Important
Entity Mapping Framework for VCL is in maintenance support mode. No new features or capabilities will be incorporated into this product.
The VCL ExpressEntityMapping Framework is an object-relational mapping (ORM) tool. It allows you to access and manage data in code, without low-level database interaction and manual SQL queries. You operate with an “Entity Model” – an object-oriented reflection of the database. Data tables are collections, records are individual objects, and fields or relations are properties.
Entity Model Designer
Entity Model Designer is a standalone application that helps you visually design and customize entity models, and generate the corresponding classes in code.
Entity Model Design and Customization
The ExpressEntityMapping Framework supports the following application development techniques:
- Model-First
You can use the Entity Model Designer application to do the following:
- Visually create and modify an entity model.
- Store an entity model in a file between designer application runs.
- Generate entity class declarations and interfaces with support for LINQ expressions.
- Database-First
- You can generate an entity model from an existing database. The Entity Model Designer imports tables, their columns, keys, properties, and relationships to replicate the entire database schema. The built entity model becomes available for customization and export.
- Code-First
You can do the following to reflect a data store’s schema in code:
- Define entities as classes and table columns as their fields and properties, with full support for class inheritance.
- Use built-in attributes to register classes in the entity model and define how they map to tables. Refer to the following topic for details on these options: Entity Class Registration.
- Specify where an entity class stores its data – in its own table or the ancestor’s table.
- Mark one or more columns as a primary key for each entity class that maps to a database table. Entity class descendants inherit their primary keys from their ancestors.
- Establish entity relationships: implement code to initialize fields and properties that form associations.
Refer to the following topics for additional information:
Query and Shape Data
A data query is one of the CRUD operations available in all data stores. You can use the following techniques to retrieve data store records as entity objects if they match specific criteria:
- Database-Independent Criteria Strings
You can use a database-independent language to define a criteria expression as a string. Call the TdxCriteriaOperator.Parse or TdxCriteriaOperator.ParseList class function to parse the string into criteria operands and operators. Pass the result as a parameter to a session component’s GetObjects or Find function.
Tip
The TdxEMFDataSet component has the CriteriaText and GroupCriteriaText properties you can use to specify filter and group criteria as strings without the need to parse them first.
- LINQ Expressions
Language Integrated Query (LINQ) adds a set of methods that allow you to write SQL-like query expressions based on types and their members. LINQ expressions both improve code readability and help you validate column names used in queries at design time.
The LINQ implementation in the ExpressEntityMapping Framework is based on overloaded operators and interfaces whose function declarations replicate an entity model, its classes, and their properties. You can store query and query expression objects in variables declared as interface types to manage the lifetime of these objects automatically.
The following code is an example of a LINQ query expression that retrieves all persons under the age of 30:
AQuery := Linq. From<TPerson>(APersonExpression). Where(APersonExpression.Age < 30). OrderBy(APersonExpression.Name). Select. Take(5);
Note
The LINQ implementation is available only for Delphi compilers.
- Object-Based Criteria
You can build criteria expressions from operator and operands declared in the dxEMF.DB.Criteria unit. Each operator accepts one or more operands that can be constants, values, entity properties, or other operators. This expression model also allows you to combine simple criteria expressions.
The code example below uses a TdxBinaryOperator object and a generic GetObjects function to retrieve all persons under the age of 30.
var ACollection: IdxEMFCollection<TPerson>; ACriteriaOperator: IdxCriteriaOperator; begin ACriteriaOperator := TdxBinaryOperator.Create('Age', 30, TdxBinaryOperatorType.Less); ACollection := dxEMFSession.GetObjects<TPerson>(ACriteriaOperator); end;
The following API members accept object-based criteria expressions:
- The TdxEMFSession component’s GetObjects and Find functions.
- The TdxEMFDataSet component’s Criteria property.
Supported DevExpress Products
The following DevExpress products support the ExpressEntityMapping Framework out-of-the-box:
- The Table View in the Data Grid
- The TdxEMFDataController
- The TcxEMFLookupComboBox editor
These products work directly with entity models and can load data on demand, similar to data controllers in server mode.
Tip
The ExpressEntityMapping Framework ships with the TdxEMFDataSet component that allows you to bind an entity model to any data-aware control the same way you would bind the standard dataset component.
Supported Database Engines
- FireBird
- Firebird 1.5, Firebird 2.5.7 (with SQL dialect 3)
- Microsoft SQL Server
- Microsoft SQL Server 7.0, SQL Server 2000, SQL Server 2000 Desktop Engine (MSDE 2000), SQL Server 2005, SQL Server 2005 Express Edition, SQL Server 2008, SQL Azure Database, SQL Server 2008 R2, SQL Server 2008 R2 Express, SQL Server 2012, SQL Server 2012 Express (including LocalDB), SQL Server 2014, SQL Server 2014 Express (including LocalDB), SQL Server 2016, SQL Server 2016 Express (including LocalDB)
- MySQL
- MySQL Server 4.1, MySQL Server 5.0, MySQL Server 5.1, MySQL Server 5.7
- Oracle
- Oracle 9i, Oracle 10g, Oracle 11g, Oracle 12c
- SQLite
- SQLite 3
- Microsoft Access
- Microsoft Access 95-2010
Tip
The ExpressEntityMapping Framework supports FireDAC and dbGo ADO connection components. You do not need additional connections in an existing application.
Refer to the following topics for details: