Entity Framework Core Data Type Mapping
On this page
dotConnect for Snowflake supports Entity Framework Core 3.1, 8, 9, 10, and 11.
Snowflake to .NET Type Mapping
The following table shows the type mappings used when you generate a model from an existing schema by running Scaffold-DbContext in Package Manager Console or dotnet ef dbcontext scaffold in the .NET CLI.
Snowflake Data Type | Store Type in the Model | .NET |
| NUMBER(p, 0) (INT, INTEGER, BIGINT, SMALLINT, TINYINT, BYTEINT) | NUMBER(p, 0) | System.Int64 for p greater than 9 or not specified; System.Int32 for p from 5 to 9; System.Int16 for p = 3 or 4; System.Byte for p = 1 or 2 |
| NUMBER(p, s) with s greater than 0 (DECIMAL, NUMERIC) | NUMBER(p, s) | System.Decimal |
| FLOAT (FLOAT4, FLOAT8, DOUBLE, DOUBLE PRECISION, REAL) | FLOAT | System.Double |
| BOOLEAN | BOOLEAN | System.Boolean |
| VARCHAR (STRING, TEXT, CHAR, CHARACTER, NCHAR, NVARCHAR, NVARCHAR2, CHAR VARYING, NCHAR VARYING) | VARCHAR, VARCHAR(n) | System.String |
| BINARY (VARBINARY) | BINARY, BINARY(n) | System.Byte[] |
| DATE | DATE | System.DateTime |
| TIME | TIME | System.TimeSpan |
| TIMESTAMP_NTZ (DATETIME, TIMESTAMP) | TIMESTAMP_NTZ | System.DateTime |
| TIMESTAMP_LTZ | TIMESTAMP_LTZ | System.DateTime |
| TIMESTAMP_TZ | TIMESTAMP_TZ | System.DateTimeOffset |
| VARIANT | VARIANT | System.String |
| OBJECT | OBJECT | System.String |
| ARRAY | ARRAY | System.String |
| GEOGRAPHY | GEOGRAPHY | System.String |
| GEOMETRY | GEOMETRY | System.String |
.NET to Snowflake Type Mapping
The following table shows the type mappings used when you create a database from a model through Code First, migrations, or EnsureCreated, and when you use parameters and literals in queries.
.NET | Snowflake Data Type |
| System.Int64 | NUMBER(19, 0) |
| System.Int32 | NUMBER(10, 0) |
| System.Int16 | NUMBER(5, 0) |
| System.Byte, System.SByte | NUMBER(3, 0) |
| System.Double, System.Single | FLOAT |
| System.Decimal | NUMBER(38, 10); NUMBER(p, s) if precision and scale are specified |
| System.Boolean | BOOLEAN |
| System.String | VARCHAR; VARCHAR(n) if the maximum length is specified |
| System.Byte[] | BINARY; BINARY(n) if the maximum length is specified |
| System.Guid | VARCHAR(36) (the value is stored as text) |
| System.DateTime | TIMESTAMP_NTZ |
| System.DateTimeOffset | TIMESTAMP_TZ |
| System.TimeSpan | TIME |
| System.DateOnly1 | DATE |
| System.TimeOnly1 | TIME |
1 Entity Framework Core 8 and later.
Notes
- INT, INTEGER, BIGINT, SMALLINT, TINYINT, and BYTEINT are aliases of NUMBER with the scale 0 in Snowflake (NUMBER(38, 0) when no precision is specified), so the declared alias isn't stored in the table schema. The .NET type of such a column in a scaffolded model depends on its precision, as shown in the first table. You can change the property type manually if the values fit into the range of the other type.
- Integer properties don't keep their types when you scaffold a database that was created with Code-First. Code-First creates a column with the smallest precision that holds every value of the .NET type: NUMBER(10, 0) for System.Int32, NUMBER(5, 0) for System.Int16, and NUMBER(3, 0) for System.Byte. Database-First chooses the .NET type by the precision of the column: System.Int64 for a precision greater than 9, System.Int32 for 5 to 9, System.Int16 for 3 and 4, and System.Byte for 1 and 2. Such columns can store values outside the range of the original type, for example, NUMBER(10, 0) can store 9999999999, which is greater than the maximum System.Int32 value. Because of this, these columns are scaffolded as System.Int64, System.Int32, and System.Int16. Note that the chosen type doesn't always hold every value of the column: a NUMBER(1, 0) or NUMBER(2, 0) column can contain negative values, which System.Byte can't hold, and a column with a precision greater than 18, including NUMBER(38, 0), can contain values outside the System.Int64 range. If you need the original types, change the property types in the scaffolded classes.
- You can map a property to another compatible type with the HasColumnType method or the Column attribute. For example, map System.DateTime to DATE or TIMESTAMP_LTZ, or System.Decimal to FLOAT.
- VARIANT, OBJECT, ARRAY, GEOGRAPHY, and GEOMETRY values are represented by System.String: JSON text for the semi-structured types, and WKT, WKB (hex), or GeoJSON text for the geospatial types. To use a string property with such a column, specify the type with the HasColumnType method. When the value is written, the provider wraps it in PARSE_JSON, TO_GEOGRAPHY, or TO_GEOMETRY, and because of this, an INSERT statement for such an entity is generated as INSERT ... SELECT instead of INSERT ... VALUES.
- The provider returns VARIANT, OBJECT, and ARRAY values as JSON text in the format returned by Snowflake. JSON objects and arrays can contain indentation and line breaks. The provider doesn't translate LINQ expressions that access paths within JSON values. To query individual JSON elements, use raw SQL. For more information, see Working with Raw SQL and Working with Semi-Structured Data.
- The Snowflake TIME type holds a time of day from 00:00:00 to 23:59:59.999999999. A System.TimeSpan value outside this range can't be used as a literal and causes an exception.
- Snowflake doesn't enforce primary keys, unique keys, and foreign keys, and standard tables have no indexes. See Mapping.
- Integer keys are generated with sequences. See Generating Key Values.