Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Insert<T>() in MySQL always return 0

Open hoquangthaiholy opened this issue 11 years ago • 19 comments

I have a problem about Insert(). When I use MSSQL for my DB. I inserted a record, this method return a long value, it is ID of new record. But in MySQL, I alway receive 0 from Insert method.

hoquangthaiholy avatar Nov 19 '15 18:11 hoquangthaiholy

Could you please give some more info? How is the table defined with the id column? Can you paste some sample code?

johandanforth avatar Nov 19 '15 18:11 johandanforth

I defined my table:

[Table("BaoQuan")]
    public class BaoQuan
    {
        [Key]
        public int id { get; set; }
        public string tenthbq { get; set; }
        [Computed]
        public int cntHopSo { get; set; }
        [Computed]
        public int cntHoSo { get; set; }
        [Computed]
        public int cntVanBan { get; set; }
    }

and then using Insert method

using(MySqlConnection con = new MySqlConnection(connectionString)){
     long i = con.Insert(new BaoQuan() { 
            tenthbq = "Tên phông",
            cntHopSo = 0,
            cntHoSo = 0,
            cntVanBan = 0 
    });
     ...
}

record insert successfully but still return 0

hoquangthaiholy avatar Nov 20 '15 01:11 hoquangthaiholy

Looks good. How is your table defined in MySQL? CREATE TABLE .... and such? Is the ID column set in the database properly? Which version of MySQL are you running?

johandanforth avatar Nov 20 '15 06:11 johandanforth

This is my table defined inMYSQL

CREATE TABLE `baoquan` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `tenthbq` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

This is my MySQL information:

Server: 127.0.0.1 via TCP/IP
Server type: MySQL
Server version: 5.6.24 - MySQL Community Server (GPL)
Protocol version: 10
User: root@localhost
Server charset:  UTF-8 Unicode (utf8)

I'm using Dapper 1.43, Dapper.Contrib 1.44

hoquangthaiholy avatar Nov 20 '15 07:11 hoquangthaiholy

Thanks ill try to investigate this weekend. Unless someone beats me to it.

johandanforth avatar Nov 20 '15 08:11 johandanforth

Please update nuget packge. Thanks

hoquangthaiholy avatar Nov 25 '15 01:11 hoquangthaiholy

Will do as soon as I figure out how to get things to compile. I'm completely new to the DNX stuff. /cc @NickCraver I got a fresh install of vs2015 but obviously I need to update the sdk or something because I get thousands of errors because of missing .NET Platform 5.4 references. Tried using dnvm to update to 1.0.0-rc1-final but things still fail in VS... help? :D

johandanforth avatar Nov 25 '15 06:11 johandanforth

i'm trying to compile from new source code. I hope everything should work. :D

hoquangthaiholy avatar Nov 25 '15 07:11 hoquangthaiholy

Heh, good luck mate, I'm down to 30.000 error messages right now... I so need to read up on the new .NET dnx stuff. I thought I could install VS2015, open a solution and rock... :/

johandanforth avatar Nov 25 '15 08:11 johandanforth

@johandanforth did you install the ASP.NET 5 RC1 tooling? -> https://get.asp.net/

henkmollema avatar Nov 25 '15 08:11 henkmollema

No I did not! Must be it. Jeez, I feel old... been deep into customer projects this year and missed alot of the new stuff. Who moved my cheese!!? :D

johandanforth avatar Nov 25 '15 08:11 johandanforth

@Johan if only somebody who has felt this pain took the time to walk through the new tools ;p

http://blog.marcgravell.com/2015/11/the-road-to-dnx-part-1.html http://blog.marcgravell.com/2015/11/the-road-to-dnx-part-2.html http://blog.marcgravell.com/2015/11/the-road-to-dnxpart-3.html

On 25 November 2015 at 08:53, Johan Danforth [email protected] wrote:

No I did not! Must be it. Jeez, I feel old... been deep into customer projects this year and missed alot of the new stuff. Who moved my cheese!!? :D

— Reply to this email directly or view it on GitHub https://github.com/StackExchange/dapper-dot-net/issues/404#issuecomment-159537735 .

Regards,

Marc

mgravell avatar Nov 25 '15 09:11 mgravell

Ahh, will you marry me @mgravell :D

johandanforth avatar Nov 25 '15 09:11 johandanforth

Why did we upgraded to VS 2015 too soon? This make compiling more harder? :P

hoquangthaiholy avatar Nov 25 '15 09:11 hoquangthaiholy

@hoquangthaiholy technically, we don't need VS 2015 to build; just dnvm to get the tools, then:

git clone https://github.com/StackExchange/dapper-dot-net.git
cd dapper-dot-net
dnu restore
dnu build Dapper --configuration Release

;p

mgravell avatar Nov 25 '15 09:11 mgravell

#410 actually broke a few things - which supports my wanting to add automated tests against Postgres and MySQL on Contrib (and hopefully later, Core...but that's much more work).

MySQL tests are now here: https://github.com/StackExchange/dapper-dot-net/commit/6ed2f3baa97b475291dd16106199021e6a6adff0 and we're looking at how to have them not break everyone who isn't running MySQL for the test suite. That'll happen before a master merge (as will connection string cleanup across all tests). If you're not running that test suite, my desire if for them to "skip" in the runner - and Appveyor will do that sanity testing for us if you don't have the various database servers installed locally.

Hang on, we're working to improve the state of affairs here :) I'll take a look at the Insert<T, TKey> and such which will better support MySQL (e.g. Insert<tableType, long>) as well...I just wanted a healthy and automated test suite before we attack that.

NickCraver avatar Nov 25 '15 11:11 NickCraver

Ok, I'm going to sit back and let you guys iron things out for a bit and read up on the "dnx stuff" for a while. Looking at Marcs articles now (super), trying out dnu, dnvm and managed to build dapper just fine... just to learn that these tools will be replaced :) moving targets here... :D @NickCraver or @mgravell feel free to build a beta-package of Dapper.Contrib if you like until I learn my ways around dnx. Marc is co-owner of the nuget package.

BTW. There's a "compile" reference in ? Dapper.Contrib/Project.json which references ../Dapper/TypeExtension.cs that I'm not sure why it's there:

"compile": [ "*/.cs", "../Dapper/TypeExtensions.cs" ],

johandanforth avatar Nov 25 '15 13:11 johandanforth

I compiled without any error. But I'm check Dapper.Contrib.

File version: 1.40.0.0. Product version: 1.50.0-beta3. <--- This version is really beta-3 ? :P

I'm using Windows 10. Visual Studio 2015 Community Edition. Thanks @mgravell for shell scripts.

hoquangthaiholy avatar Nov 26 '15 04:11 hoquangthaiholy

i hope you will do it.

tvkhoa17 avatar Nov 26 '15 08:11 tvkhoa17