Page 1 of 1

Field has no default value

Posted: Fri 12 Sep 2014 09:34
by dankolle
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

Re: Field has no default value

Posted: Fri 12 Sep 2014 20:39
by dankolle
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?

Re: Field has no default value

Posted: Tue 16 Sep 2014 12:15
by MariiaI
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.