DataLinq + MySQL & MariaDB
DataLinq provides unified support for both MySQL and MariaDB through the DataLinq.MySql NuGet package. It uses the MySqlConnector ADO.NET driver.
What This Provider Actually Covers
This provider does three distinct jobs:
- runtime access through
DataLinq.MySql - metadata introspection from
information_schema - SQL generation for MySQL and MariaDB
That matters because MariaDB-specific behavior only appears when the connection type and factory selection are actually MariaDB-aware.
Schema Introspection and Type Mapping
create-models reads schema metadata from information_schema and maps backend types to C# types. The mapping is aware of signedness, length, defaults, foreign keys, indices, and enum definitions.
| MySQL/MariaDB Type | Maps to C# Type |
|---|---|
INT UNSIGNED |
uint |
INT |
int |
BIGINT UNSIGNED |
ulong |
BIGINT |
long |
SMALLINT |
short |
TINYINT |
sbyte |
TINYINT UNSIGNED |
byte |
BIT(1) |
bool |
DECIMAL |
decimal |
DOUBLE, FLOAT |
double, float |
VARCHAR, TEXT, CHAR, etc. |
string |
DATE |
DateOnly |
DATETIME, TIMESTAMP |
DateTime |
TIME |
TimeOnly |
ENUM |
generated C# enum |
BINARY(16) |
Guid |
BLOB, VARBINARY, etc. |
byte[] |
JSON |
string |
UUID (MariaDB only) |
Guid |
Additional notes:
SETis treated asstringBINARY(16)is the normalGuidrepresentation- enums are emitted as generated C# enums with value metadata
Default Value Handling
create-models imports MySQL and MariaDB defaults into DataLinq metadata instead of treating them as raw schema text.
That includes:
- quoted string defaults
- quoted numeric defaults such as
DEFAULT '0', converted to the actual C# property type instead of being treated as strings - enum defaults, including enum labels reported from schema metadata
CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP- MySQL/MariaDB temporal aliases such as
NOW(),LOCALTIME, andLOCALTIMESTAMP - parenthesized defaults such as
(0)and('abc')
This matters because MySQL and MariaDB are loose about how defaults are represented in schema metadata. DataLinq normalizes the SQL literal first, then converts it according to the target property type.
Examples:
INT DEFAULT '0'-> C#intdefault0BIGINT DEFAULT '0'-> C#longdefault0LENUM('standard','premium') DEFAULT 'premium'-> generated enum member defaultVARCHAR DEFAULT '""'-> C# string default containing two double-quote characters, not leaked SQL quoting syntax
Unsupported or Dangerous Defaults
Zero-date defaults such as 0000-00-00 and 0000-00-00 00:00:00 are not generated into typed date properties.
DataLinq warns and skips those defaults instead of emitting broken C# or pretending that invalid MySQL date garbage is fine.
MariaDB-Specific Features
MariaDB can use a native UUID type. DataLinq supports that, but only when you actually use MariaDB-specific type metadata.
Native UUID Type
- Reading schema: A MariaDB
UUIDcolumn maps toGuid. - Generating schema: To emit a native MariaDB
UUID, use[Type(DatabaseType.MariaDB, "uuid")]. - Default behavior: MariaDB SQL generation prefers native
UUIDfor plainGuidproperties.
Provider Configuration
To leverage MariaDB-specific behavior, make sure your datalinq.json connection is marked as MariaDB:
"Connections": [
{
"Type": "MariaDB",
"DataSourceName": "my_mariadb_database",
"ConnectionString": "..."
}
]
If you mark the connection as MySQL, you are asking DataLinq to behave like MySQL even if the server happens to be MariaDB.
Important Guid Caveat
Guid values stored as BINARY(16) depend on MySqlConnector GuidFormat=LittleEndianBinary16 behaving the way the tests expect.
Native MariaDB UUID avoids that pain. BINARY(16) does not. This is a real caveat, not a theoretical one.
SQL Generation
When generating a schema from your DataLinq models:
- MySQL maps
GuidtoBINARY(16)by default - MariaDB maps
Guidto nativeUUIDby default - view definitions use
CREATE OR REPLACE VIEW
Default SQL generation is typed, not stringly:
- string and char defaults are SQL-quoted and escaped correctly
bitdefaults are emitted asb'0'andb'1'- numeric defaults use invariant formatting
DateOnly,TimeOnly,DateTime, and related values are emitted as provider-safe SQL literals- MariaDB
uuiddefaults and MySQLbinary(16)Guiddefaults are emitted differently because they are genuinely different storage shapes
If DataLinq can parse a supported MySQL/MariaDB default and represent it in metadata, it should also be able to emit it back out correctly in generated SQL. That roundtrip is now something the test suite actually checks.
Transaction Behavior
The current MySQL and MariaDB transaction implementation opens transactions with IsolationLevel.ReadCommitted.
That is relevant when comparing provider behavior to SQLite. Do not write cross-provider transaction visibility tests that assume they behave the same.