LINQ / MySQL / AutoIncrement

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
paulb
Posts: 1
Joined: Mon 06 Jun 2011 08:45

LINQ / MySQL / AutoIncrement

Post by paulb » Mon 06 Jun 2011 09:16

Hello,

With the following code:

Code: Select all

[Table]
public class Customer
{
    [Column( IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert )]
    public int Id { get; set; }
    ...
}

public class Database
{
    public static void Create( DataContext context )
    {
        if( !context.DatabaseExists() )
        {
            context.GetTable();

            context.CreateDatabase();
            context.SubmitChanges();
        }
    }
}

The Id field won't have auto increment set in the MySQL database. When I attempt to insert an object an exception is thrown saying that Id doesn't have a default value. I want MySQL to assign the value automatically.

The only solution I could think of was to use a MySqlCommand to alter the table after the database is created - is there a better way?

Thanks,

Paul

Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Post by Zero-G. » Tue 07 Jun 2011 14:48

Hey

I took a look into my generated vb files.
What I saw there, is that you don't have any kind of DBType in you declaration. - Maybe this is the problem.

Try to add: DbType := "BIGINT(19) NOT NULL")> _ after the AutoSync Property.

As I sayed:
1) I use VB.NET
2) The generated code was build with the latest available components

Maybe it will help!?

Have a nice day

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 07 Jun 2011 15:40

Thank you for the report. We have changed this behaviour so that an auto-incremented column is created if all of the following conditions are met:
- the corresponding entity member is auto-generated and is a part of the entity key;
- this entity member is of an integer type (e.g., Int16 or Int32);
- the IdGenerator property of this member is 'none' or 'Identity';
- this is the only member of this entity class that satisfies the above conditions.

These changes will be available in the nearest build. We will post here when this build is available.

As a temporary workaround, you can use the 'alter' command.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 17 Jun 2011 16:28

We have released the new 2.50.25 build of LinqConnect, which includes the fix for the problem with auto-increment fields not being generated by the CreateDatabase method. The new build can be downloaded from
http://www.devart.com/linqconnect/download.html
(the trial and free versions) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For the information about other fixes and improvements available in LinqConnect 2.50.25, please refer to
http://www.devart.com/forums/viewtopic.php?t=21284

Post Reply