Migrations
By convention, ODP.NET EF Core maps an appropriate database data type based on the .NET data type and its characteristics. This table shows the default mappings. Fluent APIs/Annotations can be used to map the .NET types to any valid Oracle data type.
This table shows the default mappings. Fluent APIs and Data Annotations can be used to map the .NET types to any valid Oracle data type.
Table 5-1 ODP.NET Entity Framework Core Migrations Data Type Default Mappings
.NET Type Alias | .NET Data Type | Required Fluent API(s)* | Oracle Database Data Type |
---|---|---|---|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
None |
|
|
|
|
|
|
|
|
|
|
|
None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
None |
|
* Corresponding data annotations can also be used instead of the specified fluent APIs.
NCHAR
and NVARCHAR2
use character length semantics. The number of characters for columns with one of these data types depend on the character set, NLS_NCHAR_CHARACTERSET
. ODP.NET Entity Framework Core defaults to a 2-byte character set, which allows a maximum of 2000 characters for NCHAR
and NVARCHAR2
columns. If a [Maxlength(4000)] data annotation or fluent API equivalent is used for a string entity property, ODP.NET will map the property to an NCLOB
type because the specified length is greater than 2000 characters.
For example, if a NVARCHAR2(4000)
column on the database NLS_NCHAR_CHARACTERSET
or if the NVARCHAR2
column has a maximum 32 KB length (i.e. MAX_STRING_SIZE = EXTENDED
), the string entity property can use the [Column] data annotation or a fluent API equivalent to map to an N-character data type, rather than mapping to the default NCLOB
. Here's an example of using such an annotation:
[Column("Name", TypeName = "NVARCHAR2(4000)")] string EmployeeName
Applications may prefer N-character data types over NCLOB
s as they require no additional server roundtrips to fetch and update data.
Synonyms
EF Core migrations can generate arbitrary Oracle schema objects using the RelationalDatabaseFacadeExtensions
class, such as using the ExecuteSqlRaw
method to perform DDL on those objects. For example, to create a synonym for the Blogs table sample, the following code snippet can be used:
private static void SetupDatabase() { using (var db = new BloggingContext()) { db.Database.EnsureDeleted(); if (db.Database.EnsureCreated()) { //other code #region Synonym db.Database.ExecuteSqlRaw( " create synonym s for \"Blogs\";"); #endregion db.SaveChanges(); } } }