Srini-komman / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Specified cast is not valid #175

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am using C# with Dapper and MySQL.

Dapper dot net version: 1.25
Dapper Extensions version: 1.4.3
MySQL.Data version: 6.8.3

So i have these entities:
https://gist.github.com/Cortz/b1ce115e53560dc6616a

When i try to do an insert to my MySQL database, the data gets inserted but 
then my Insert throws an exception:
"An exception of type 'System.InvalidCastException' occurred in Dapper.dll but 
was not handled in user code

Additional information: Specified cast is not valid."

Inser method: https://gist.github.com/Cortz/bae2e6814f9326e3eeab

Stack trace:
https://gist.github.com/Cortz/a7e765e01fb161a8d83b

As you can see the problem happens here in dapper:
https://github.com/StackExchange/dapper-dot-net/blob/master/Dapper%20NET40/SqlMa
pper.cs Line: 1155 

(yield return (T)Convert.ChangeType(val, typeof(T));)

My MySQL table:
https://db.tt/lroUM3hJ

I can't seem to find out what's making this happen, buy maybe you guys have 
seen it before? Been googling around, and everyone is telling me that i have to 
insert Convert Zero Datetime and Allow Zero Datetime to my connection string, 
but do not solve my problem.

Original issue reported on code.google.com by madsco...@gmail.com on 23 May 2014 at 11:23

GoogleCodeExporter commented 8 years ago
This was an error in Dapper Extensions - MySqlDialect.cs:

Changed the GetIdentitySql(string tableName) from:
public override string GetIdentitySql(string tableName)
        {
            return "SELECT LAST_INSERT_ID() AS Id";
        }

to:
public override string GetIdentitySql(string tableName)
        {
            return "SELECT CONVERT(LAST_INSERT_ID(), SIGNED INTEGER) AS ID";
        }

Please close this report

Original comment by madsco...@gmail.com on 24 May 2014 at 8:38