Page 1 of 1

[Solved] Auto-Increment BigInt causes InvalidCastException

Posted: Thu 07 Mar 2013 10:11
by steffen_w
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.

Re: [Solved] Auto-Increment BigInt causes InvalidCastException

Posted: Thu 07 Mar 2013 13:19
by MariiaI
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.

Re: [Solved] Auto-Increment BigInt causes InvalidCastException

Posted: Fri 15 Mar 2013 08:12
by MariiaI
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.