Friday, February 15, 2013

ADO.NET EF duplicates/overrides data (Oracle)

Hello,

In my current project we are using ADO.NET Entity Framework 4 (Oracle implementation).
Today, one of my users noticed that in some data grid the rows were duplicated (that was in the UI).

I found out the LINQ query that got the data from the DB and there's nothing wrong with it (at a glance). Running the equivalent (not the one the EF generates) SQL query, brought back correct data. Debugging on the server revealed that the data was indeed duplicated (actually, it was overridden - the second row was the same as the first). This gave me the idea to look inside the model. I looked inside model's PKs of the generated and it looked like there were wrongly generated - 6 columns were PKs.

The solution was to put only one PK (fortunately I had such a column) and fix some null columns errors.
If you don't have one, you can generate one - see previous post!

Now the data is the same as the SQL query returned.

Happy day...! :)

No comments: