very strange

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
hepek
Posts: 115
Joined: Thu 07 Jul 2011 13:59

very strange

Post by hepek » Fri 30 Mar 2012 19:08

I have a table and part of the PK is column CounterID.

consider this statement:

Code: Select all

         var query = DB.CompStyles
                         .Where( q => q.DealNumber == dealNum &&
                                 q.JobNumber == jobNum &&
                                 q.CycleNumber == cycleNum);
this query returns 3 records, which is expected.

When I update entity definition and mark CounterID as NOT Primary Key, and I run the same query above and get the 3 records back, but they all point to the first record. Basically the set of 3 rows are all the same row with a same CounterID. As you can see my query is not even using the CounterID property.

The reason I tried to mark CounterID as NOT PK is to go around some other problem.
(reported here: http://www.devart.com/forums/viewtopic. ... 9997#79997)

PK for the table is: DealNumber, JobNumber, CycleNumber and CounterID

Don't you find this very strange? Thanks.

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

Post by MariiaI » Wed 04 Apr 2012 07:45

Could you please send us the model you are working with and the SQL script for creating the table "CompStyles" so that we can reproduce this issue.

hepek
Posts: 115
Joined: Thu 07 Jul 2011 13:59

Post by hepek » Wed 04 Apr 2012 13:45

thank you Mariia, I emaild you everything you asked for

regards

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

Post by MariiaI » Thu 05 Apr 2012 09:43

This happens because LinqConnect uses Object Identity as the way of the object identifier caching.
Every time when some row is fetched from the database, it is saved in a special cache with the help of its primary key. This row can be identified by its primary key value. If we want to query this record next time, object will be loaded from the hash-table instead of being materialized from the query result.

That's why after you have excluded CounterID from the entity primary key, you get such results. The rows that have the same values of other primary key columns are considered as the same entity, which therefore is loaded from the cache. To avoid such situations, you can either keep PK the same in the model and in the database, or remove all fields from the PK in the model.

For more information see:
http://www.devart.com/linqconnect/docs/ ... ntity.html
http://www.devart.com/linqconnect/docs/ObjectCache.html

hepek
Posts: 115
Joined: Thu 07 Jul 2011 13:59

Post by hepek » Wed 18 Apr 2012 16:45

Hi Mariia,

thank you for the detailed explanation.

Post Reply