[Solved] Auto-Increment BigInt causes InvalidCastException

[Solved] Auto-Increment BigInt causes InvalidCastException

Postby steffen_w » Thu 07 Mar 2013 10:11

Hi,

I got a MySQL database which, on some tables, has an auto-incremented BigInt as PK. When I try to add a new object to the table I get an 'InvalidCastException' on SubmitChanges().

I know that that is the problem because for testing I removed the auto_increment from LinqConnect on that property and set the 'IsDbGenerated' property to false and filled the field with a random number and it worked. After I changed everything back again, I get the InvalidCastException again.

The field as it is declared in the autogenerated *.cs file:
Code: Select all
[Column(Storage = "_ID", AutoSync = AutoSync.OnInsert, CanBeNull = false, DbType = "BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT", IsDbGenerated = true, IsPrimaryKey = true)]
        public decimal ID
        {
            get
            {
                return this._ID;
            }
            set
            {
                if (this._ID != value)
                {
                    this.OnIDChanging(value);
                    this.SendPropertyChanging();
                    this._ID = value;
                    this.SendPropertyChanged("ID");
                    this.OnIDChanged();
                }
            }
        }


My LinqConnect version is 4.1.197. My EntityDeveloper version is 5.0.56.

Got it fixed. Problem was that it was a decimal in .NET, after I changed it to System.UInt64 it worked.
steffen_w
 
Posts: 16
Joined: Wed 06 Mar 2013 14:28

Re: [Solved] Auto-Increment BigInt causes InvalidCastException

Postby MariiaI » Thu 07 Mar 2013 13:19

Thank you for the report. We have reproduced this issue; you are right - the problem is in decimal datatype. We will investigate it and inform you about the results as soon as possible.

Glad to see that you find the workaround. If you have any further questions, feel free to contact us.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: [Solved] Auto-Increment BigInt causes InvalidCastException

Postby MariiaI » Fri 15 Mar 2013 08:12

The bug related to the "Specified cast is not valid" exception when working with auto-increment primary keys mapped to decimal entity property is fixed. It is available in the new build of LinqConnect 4.1.207.
New build can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=26200.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to LinqConnect (LINQ to SQL support)