This question is locked. New answers and comments are not allowed.
I encountered the following issue: whenever I create a base class and a derived class (using Flat Mapping), and I update the property of an instance of the derived class, I get an OptimisticVerificationException:
"Row not found: GenericOID@5 Cat Id=3
UPDATE [Animals] SET [MiceEaten]=? WHERE [Id] = ? AND [MiceEaten]=?"
(see also attached screenshot).
To reproduce the problem one may follow these steps:
When you run the program you will receive an OptimisticVerificationException.
To avoid the exception, you need to set the "MiceEaten" column to an integer value that is not NULL, e.g. 0 for all Cat records.
After we do that and run the code again, it will work.
I don't think the error is supposed to happen, because during development it may very well happen more than once that I need to add a property to some derived class, updating the database with a migration script, which will leave the newly generated column with NULL values (unless of course I modify the migration update script and use 0 as the default value to avoid the OptimisticVerificationException).
A sample project demonstrating the problem can be downloaded from here (including a SQL Compact database with preconfigured data).
Detected another smaller issue: There seems to be a bug that causes mapped properties to be NULLABLE, even though the Table is defined with NOT NULL columns. I have to manually set "Nullable" to false for these properties (I also need to do so for the Id property, otherwise OA generates an error messagebox when I want to update the database, which prevents me from doing so).
Regards,
Skywalker
"Row not found: GenericOID@5 Cat Id=3
UPDATE [Animals] SET [MiceEaten]=? WHERE [Id] = ? AND [MiceEaten]=?"
(see also attached screenshot).
To reproduce the problem one may follow these steps:
- Create a new EntityDiagrams file
- Using the "Model First" approach, define a table called "Animals" with the columns: Id, Age, MiceEaten (all int NOT NULL)
- Create the base model called "Animal" and a derived model called "Cat". Map the "MiceEaten" column to the "Cat" model. "Id" and "Age" must be mapped to the "Animal" model class.
- Create the database and generate the tables. Create a few records, all of which "MiceEaten" will be NULL (although we defined "MiceEaten" to be non-nullable, the column must be generated as nullable because other derived classes, such as Dog, do not have a "MiceEaten" property, thus records of type "Dog" will have its 'MiceEaten" column set to NULL.
- Write a simple Console program that loads one or more Cats, update the "MiceEaten" property with some value, and call SaveChanges.
When you run the program you will receive an OptimisticVerificationException.
To avoid the exception, you need to set the "MiceEaten" column to an integer value that is not NULL, e.g. 0 for all Cat records.
I don't think the error is supposed to happen, because during development it may very well happen more than once that I need to add a property to some derived class, updating the database with a migration script, which will leave the newly generated column with NULL values (unless of course I modify the migration update script and use 0 as the default value to avoid the OptimisticVerificationException).
A sample project demonstrating the problem can be downloaded from here (including a SQL Compact database with preconfigured data).
Detected another smaller issue: There seems to be a bug that causes mapped properties to be NULLABLE, even though the Table is defined with NOT NULL columns. I have to manually set "Nullable" to false for these properties (I also need to do so for the Id property, otherwise OA generates an error messagebox when I want to update the database, which prevents me from doing so).
Regards,
Skywalker