Skip to content

Commit ee95886

Browse files
committed
Document Connector/NET's implicit conversions. Fixes #408
1 parent 19c2a2d commit ee95886

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/content/tutorials/migrating-from-connector-net.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ MySqlConnector has some different default connection string options:
6464
Some connection string options that are supported in Connector/NET are not supported in MySqlConnector. For a full list of options that are
6565
supported in MySqlConnector, see the [Connection Options](connection-options).
6666

67+
### Implicit Conversions
68+
69+
Connector/NET allows `MySqlDataReader.GetString()` to be called on many non-textual columns, and will implicitly
70+
convert the value to a `string` (using the current locale). This is a frequent source of locale-dependent bugs, so
71+
MySqlConnector follows typical ADO.NET practice (e.g., SqlClient, npgsql) and disallows this (by throwing an `InvalidCastException`).
72+
73+
To fix this, use the accessor method (e.g., `GetInt32`, `GetDouble`) that matches the column type, or perform an
74+
explicit conversion to `string` by calling `GetValue(x).ToString()` (optionally supplying the right `CultureInfo` to use
75+
for formatting).
76+
6777
### TransactionScope
6878

6979
MySqlConnector adds full distributed transaction support (for client code using [`System.Transactions.Transaction`](https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transaction

0 commit comments

Comments
 (0)