Zen ADO.NET Entity Framework Core Data Providers
Zen ADO.NET Entity Framework (EF) Core is a lightweight and extensible object-relational mapper (O/RM) for .NET that supports cross-platform development. It allows developers to work with the database using .NET objects and helps them decrease the amount of code that needs to be written and maintained in data-centric applications.
Zen ADO.NET Entity Framework Core data providers can be used with applications that use the ADO.NET Entity Framework Core. They support the following:
• Microsoft ADO.NET Entity Framework Core 8.0
Zen ADO.NET Entity Framework Core data providers use ADO.NET data providers to communicate with ADO.NET database servers. This means that the functionality defined by Zen ADO.NET data providers applies to Zen ADO.NET Entity Framework Core data providers unless otherwise noted here. Similarly, any performance configurations made to Zen ADO.NET data providers are realized by the Zen ADO.NET Entity Framework Core data providers.
Note: Visual Studio 2022 or later is required when developing applications for the Zen ADO.NET Entity Framework Core.
About Zen ADO.NET Entity Framework Core Data Providers
Zen ADO.NET Entity Framework Core data providers are built with 100% managed code, so they can run and connect to the database entirely within the common language runtime (CLR).
Code that runs in the native operating system, such as client libraries and COM components, is called unmanaged code. You can mix managed and unmanaged code within a single application. However, unmanaged code reaches outside the CLR, which means that it effectively raises complexity, reduces performance, and opens possible security risks.
Namespace
The namespace for the Zen ADO.NET Entity Framework Core data provider is Actian.EntityFrameworkCore.Zen.
Assembly Names
The Zen ADO.NET Entity Framework Core data provider uses the assembly name Actian.EntityFrameworkCore.Zen.dll.
To use it, download the latest SDK .zip archive and extract the NuGet package Actian.EntityFrameworkCore.Zen for your version as listed under
Zen ADO.NET Data Providers Available with SDK Download. Then add the package to your project.
Configuring the Zen ADO.NET Entity Framework Core Data Provider
To configure Zen ADO.NET Entity Framework Core Data Provider
2. Install the following NuGet package: Actian.EntityFrameworkCore.Zen.
3. Add a new context class to your application and override the OnConfiguring method using the following code:
public class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseZen(connection string);
}
Using Connection Strings with the Zen ADO.NET Entity Framework Core Data Provider
The Zen ADO.NET Entity Framework Core data provider uses information contained in connection strings to connect to the underlying Zen ADO.NET data provider that supports the Entity Framework Core.
Changes in Default Values for Connection String Options
Most default values of the connection string options used by the Zen ADO.NET Entity Framework Core data provider are the same as those used by the Zen ADO.NET data provider. See
Connection String Properties for more information and a list of connection string options that have a different default value when used with an ADO.NET Entity Framework Core application.
Code First Support
Entity Framework Core supports Code First features. Implementing support for these features requires changes to the data provider, including those required to handle long identifier names. However, it does not need any changes to your application.
Code First implementations require type mapping changes. See
Type Mapping for Code First for more information.
Handling Long Identifier Names
Most Zen identifiers have a maximum length of 20 bytes. The identifier name can exceed this size because the names of the objects to be created on the server are taken from the class and property names. In addition, constraint names are often created by concatenating several object names. In these cases, the chances of exceeding the maximum identifier length are even greater.
For columns, the data provider shortens identifiers to the maximum identifier length allowed by the database, replacing the end of the identifier with a tilde character ~. For example, the string ColumnMoreThanTwentyCharacters is shortened to ColumnMoreThanTwent~.
For tables, the data provider shortens identifiers to the maximum identifier length allowed by the database, replacing the end of the identifier with an integer hash-code. For example, the string ATableWithAVeryLongTableName is shortened to ATableWit_1738385675.
If you access or view the DB object using a DB tool, the names of the created tables may differ from what you might expect based on model class names and property names.
Using Code First Migrations with the ADO.NET Entity Framework Core
Entity Framework Core supports the Code First Migrations feature, which enables you to update your database schema to reflect model classes without having to drop and recreate them.
Migrations enable you to incrementally evolve your database schema as your model changes. Each set of changes to the database is expressed in a code file, known as a migration. The migrations are ordered, typically using a time stamp, and a table in the database keeps track of which migrations are applied to the database.
Code First Migrations requires type mapping changes. See
Type Mapping for Code First for more information.
To implement Code First Migrations, once you have configured the Zen ADO.NET Entity Framework Core data provider, install the following NuGet package: Microsoft.EntityFrameworkCore.Tools (version 3.1)
Using Reverse Engineering (Scaffolding)
The process of scaffolding entity type classes and a DbContext class based on a database schema is called reverse engineering. You can perform it using either the Scaffold-DbContext command of the EF Core Package Manager Console (PMC) tools or the dotnet ef dbcontext scaffold command of the .NET command-line interface (CLI) tools.
To use reverse engineering with the ADO.NET Actian Zen Entity Framework Core data provider, perform the following steps after you have configured the data provider:
1. Install the following NuGet package: Microsoft.EntityFrameworkCore.Tools (version 8.0.0).
2. Run the following Scaffold-DbContext PowerShell command:
Scaffold-DbContext 'connection string' Actian.EntityFrameworkCore.Zen
You can add more parameters to the
Scaffold-DbContext PowerShell command, if required. To know more about it, see
https://docs.microsoft.com/en-in/ef/core/managing-schemas/scaffolding?tabs=vs.
Type Mapping for Code First
The following table shows the model-centric type mapping, where the CLR type influences the Zen (store) type used when the database is created. Some CLR types can map to several different Zen types.
The columns are defined as follows:
• The CLR Type column refers to the common language runtime type name.
• Property Values Affecting Type Mapping identifies any property value that can affect type mapping.
• The Zen Type column refers to the native type name.
Mapping EDM Canonical Functions to Zen Functions
The ADO.NET Entity Framework Core translates the Entity Data Model (EDM) canonical functions to the corresponding data source functionality for the Zen ADO.NET Entity Framework Core data provider. The function invocations are expressed in a common form across data sources.
Because these canonical functions are independent of data sources, argument and return types of canonical functions are defined in terms of types in the EDM. When an Entity SQL query uses canonical functions, the appropriate function is called at the data source.
Both null-input behavior and error conditions are explicitly specified for all canonical functions. However, the ADO.NET Entity Framework Core does not enforce this behavior.
Aggregate Canonical Functions
The following table describes the mapping of EDM aggregate canonical functions to Zen functions, and also the CLR types to which these functions apply.
Math Canonical Functions
The following table describes the mapping of EDM math canonical functions to Zen functions, and also the CLR types to which these functions apply.
Date and Time Canonical Functions
The following table describes the mapping of EDM date and time canonical functions to Zen functions that generate, process, and manipulate types that work with data time data, and also the CLR types to which these functions apply.
String Canonical Functions
The following table describes the mapping of EDM string canonical functions to Zen functions, and also the CLR types to which these functions apply.
Other Canonical Functions
The following table describes the mapping of other canonical functions to Zen functions, and also the CLR types to which these functions apply.
Note: Column is the property to which the function is applied.
Extending Entity Framework Functionality
The ADO.NET Entity Framework Core and Actian Zen Entity Framework Core data provider are designed to be extended easily. The following examples demonstrate how to extend Entity Framework Core:
Using Stored Procedures with the ADO.NET Entity Framework Core
In Entity Framework Core, stored procedures can be executed using raw SQL queries. For more information, see
https://docs.microsoft.com/en-in/ef/core/querying/raw-sql.
Upgrading an Application from Entity Framework 6.x to Entity Framework Core
To upgrade your application from Entity Framework 6.x to Entity Framework Core, see
https://docs.microsoft.com/en-us/ef/efcore-and-ef6/porting/.
Limitations
The Actian Zen ADO.NET Entity Framework Core data provider has the following limitations:
• The Actian Zen Entity Framework Core data provider does not support the concurrency feature of reverse engineering (scaffolding).
For More Information
Refer to the following sources for additional information about ADO.NET and the Entity Framework Core.
• Feature Comparison compares the features available in Entity Framework Core and Entity Framework 6.X.
• ASP.NET Core shows how to use Entity Framework Core in an ASP.NET Core Razor Pages app.