c# - Dapper.Contrib - Insert Converting AutoIncrement BIGINT to Int32 -
i have mysql table has bigint column primary key, , auto increment value @ 9888008450 (obviously larger 32 bit number).
when call insert function dapper.contrib, throwing exception:
value either large or small int32.
this issue happening insert function. get, insert , delete functions work fine.
here test application:
static void main(string[] args) { using (var conn = new mysqlconnection(connstring)) { try { conn.execute("drop table if exists test;"); conn.execute("create table test (accountnumber bigint(20) primary key auto_increment,name varchar(50) not null);"); conn.execute("alter table test auto_increment = " + ((long)int.maxvalue + 1)); var test = new test { name = "test name" }; conn.insert(test); console.writeline(test.accountnumber); } catch (exception ex) { console.writeline(ex.tostring()); } } console.readkey(); }
is bug dapper.contrib or need change in code?
edit:
just found github pull request
looks there no immediate plans fix this.
i created temporary workaround in code, if has better suggestion surely appreciate it:
public static long insert<t>(t entity) t : class { try { conn.insert(entity); } catch (overflowexception ex) { if (ex.targetsite.declaringtype == typeof(convert) && ex.targetsite.name == "toint32") return conn.querysingle<long>("select last_insert_id();"); } }
wiki
Comments
Post a Comment