This is a migrated thread and some comments may be shown as answers.

"OptimisticVerificationException" in case of a Derived Class (looks like a bug)

7 Answers 211 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Skywalker
Top achievements
Rank 1
Skywalker asked on 18 Apr 2011, 11:03 PM
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:

  1. Create a new EntityDiagrams file
  2. Using the "Model First" approach, define a table called "Animals" with the columns: Id, Age, MiceEaten (all int NOT NULL)
  3. 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.
  4. 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.
  5. 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.
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

7 Answers, 1 is accepted

Sort by
0
Accepted
Zoran
Telerik team
answered on 21 Apr 2011, 05:29 PM
Hi Skywalker,

 We verified the scenario you reported and you are right, this is definitely a bug on our side. We will make sure it is fixed by the next internal build.

Best wishes,
Zoran
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Muthu
Top achievements
Rank 1
answered on 07 Mar 2012, 09:51 PM
Has this bug been fixed currently, we face this bug currently in our WPF application. Please advise.
0
Zoran
Telerik team
answered on 09 Mar 2012, 01:05 PM
Hi Muthu,

 The problem regarding this scenario is a bit more complex than initially thought. The issue comes from the fact that there is a null value in the database for the MiceEaten column, however the MiceEaten property is of type int which in .NET can't hold the value of null. That is why, when the object is fetched from the database, the value of the MiceEaten property is initialized with 0(default for int) and when you update it to 15 for example, OpenAccess sees that the value of the property has changed from 0 to 15 and not from NULL to 15 as is the case in the database.

There is an easy solution to this problem though and that is to edit the MiceEaten property in the Visual Designer by setting its IsNullable property=true. That will make the designer to generate int? as the type of the property and will allow it to hold NULL which is the actual value available in the database. With this setup, the exception described in this post will not be present.

Regards,
Zoran
the Telerik team
Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
0
Yan
Top achievements
Rank 2
answered on 24 Aug 2012, 02:05 PM

Hello! problem has not been solved (for now I have the latest version) should quickly fix this thing!





Row not found: GenericOID@f14e99db VirbeeSessionState ID=184a8431-5ba8-4d02-a99a-231f73c3fefa

UPDATE [VirbeeSessionState] SET [LockDate]=?, [LockID]=?, [Locked]=? WHERE [ID] = ? AND [LockID]=? AND [Locked]=?





create table VirbeeSessionState

(

 ID UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY NOT NULL,

 SessionID nvarchar(40),

 Created datetime, --Время создание сессии.

 Expires datetime, --Время, когда истекает сессия.

 LockDate datetime, --Момент когда была заблокирована сессия.

 LockID int , --Номер блокировки сессии.

 Locked bit, -- Есть ли в данным момент блокировка.

 ItemContent varbinary(max), --Содержимое сессии в сериализованном виде.

 UserID UNIQUEIDENTIFIER, -- пользователь

)

0
Zoran
Telerik team
answered on 29 Aug 2012, 09:17 AM
Hi Yan,

 I am not sure that the problem you have faced is the same as the one discussed in this thread, even though the error messages might be alike. Can you tell us more about your scenario, how does your model look like and what are you trying to accomplish when you get the error? Do you have any inheritance at all in your model as that was part of the problem which was discussed so far?

Greetings,
Zoran
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Yan
Top achievements
Rank 2
answered on 05 Sep 2012, 09:34 AM

 

I have a problem with updating data in a table, in which the key field - UNIQUEIDENTIFIER. database - SQL Azure.

when trying to update an exception occurs that says that OpenAccess can not find an existing entry in the table to refresh



sql:

create table VirbeeSessionState

(

 ID UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY NOT NULL,

 SessionID nvarchar(40),

 Created datetime, --Время создание сессии.

 Expires datetime, --Время, когда истекает сессия.

 LockDate datetime, --Момент когда была заблокирована сессия.

 LockID int , --Номер блокировки сессии.

 Locked bit, -- Есть ли в данным момент блокировка. 

 ItemContent varbinary(max), --Содержимое сессии в сериализованном виде.

 UserID UNIQUEIDENTIFIER, -- пользователь

)
0
Zoran
Telerik team
answered on 07 Sep 2012, 10:33 AM
Hello Yan,

 The problem is really not visible with the information we have from you so far. Can we have a sample console application showing the issue or at least your .rlinq file together with some sample code that you use in order to update your entity. We need to know which properties are you trying to update and what are the value available in the database for the updated object, in order to re-create the scenario locally and eventually reproduce the exception.

Greetings,
Zoran
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
Design Time (Visual Designer & Tools)
Asked by
Skywalker
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Muthu
Top achievements
Rank 1
Yan
Top achievements
Rank 2
Share this question
or