Field has no default value

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
dankolle
Posts: 5
Joined: Sat 06 Sep 2014 19:37

Field has no default value

Post by dankolle » Fri 12 Sep 2014 09:34

I have a class with the following ID.

Name: ID
Store Generated Pattern: Identity
Entity Key: True
Nullable: False
Type: Guid
Validation Required: True

I use the POCO template.

When I now try to add a new object with a set ID, I get an error that the field ID has no default value although the value is set.

Code: Select all

var obj = new MyClass();
obj.ID = Guid.NewGuid();

context.MyClasses.AddObject(obj);

context.SaveChanges();  <--- Exception thrown
Any suggestion why it asks for a default value although a value is given?

Thanks
Daniel

dankolle
Posts: 5
Joined: Sat 06 Sep 2014 19:37

Re: Field has no default value

Post by dankolle » Fri 12 Sep 2014 20:39

One additional question.

What is the best approach to update objects with the POCO model? I saw a function ApplyCurrentValues but it says that it creates a copy. Is that the correct function?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Field has no default value

Post by MariiaI » Tue 16 Sep 2014 12:15

Any suggestion why it asks for a default value although a value is given?
Name: ID
Store Generated Pattern: Identity
Type: Guid
It is impossible to use Guid type (which corresponds to char(36)/binary(16) in MySQL) and Store Generated = Identity.
Please refer to http://dev.mysql.com/doc/refman/5.5/en/ ... table.html :
AUTO_INCREMENT applies only to integer and floating-point types.

Thus, to avoid this error please open Property Editor for the ID property and set Store Generated to None.
Some useful information can be found here:
http://www.devart.com/dotconnect/mysql/ ... pping.html
http://www.devart.com/dotconnect/mysql/ ... sGuid.html
What is the best approach to update objects with the POCO model? I saw a function ApplyCurrentValues but it says that it creates a copy. Is that the correct function?
Use the SaveChanges() method.

If the information doesn't help, please send us a test project with the DDL script for the necessary database table, with which this issue could be reproduced, so that we are able to investigate it in more details and find the solution for you in a shortest time.

Post Reply