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

[Solved] Update using primary key only

5 Answers 149 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Castgroup srl
Top achievements
Rank 2
Castgroup srl asked on 07 Apr 2010, 11:11 AM
Hi,
(orm q1 2010, sql server 2008, win vista)
I have a question about updating an object using transaction. I try to trace (with sql profiler) the query that has been executed on the db.
The update query traced by the profiler contains in the where clause all the column of the record to be updated.
Is it possible to do the same update by using only primary key without specifying all columm, like hibernate?

Below the code executed e and the query traced:
scope.Transaction.Begin();<br>machine.Note = "";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>scope.Transaction.Commit();<br><br>UPDATE [Macchina] SET [Codice]=@p0, [DataModifica]=@p1, [IdLinea]=@p2, [IdMacchinaTipo]=@p3, [Note]=@p4, [OrdinamentoSuLinea]=@p5, [IdUtenteModifica]=@p6 WHERE [IdMacchina] = @p7 AND [Codice]=@p8 AND [IdLinea]=@p9 AND [IdMacchinaTipo]=@p10 AND [OrdinamentoSuLinea]=@p11 AND [IdUtenteModifica]=@p12' 


Regards
Luca

5 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 07 Apr 2010, 01:21 PM
Hi Luca,

May I ask you what concurrency control scheme you use? (is it by version or... it seems like you are using the one that takes each and every field in the updated class with in the where clause of the generated sql)

For example, if you use concurrency control "By version" instead (it will place another column in the generated table for the version number)...eliminating the need to check each and every field for updates by other clients.

So what you are seeing here is a consequence of you concurrency control settings for the persistent class in question.

Regards

Henrik
0
Castgroup srl
Top achievements
Rank 2
answered on 07 Apr 2010, 02:25 PM
Ok, but I can set Concurrency Control Verify Method only in forward mapping,
but I'm using reverse mapping.

So: how can I set Concurrency Control Verify Method = none or changed in reverse mapping?
(probably I need to change manually reversemapping.config...)
Luca



0
Accepted
IT-Als
Top achievements
Rank 1
answered on 07 Apr 2010, 02:29 PM
Hi Luca,

I don't know if you "own" the database schema..  But you can do a forward mapping after you done a reverse mapping... That is perfectly legal. Thus you can set the concurrency control to for example By version... having in mind that this will include a version column in each of your tables.

Regards

Henrik
0
Castgroup srl
Top achievements
Rank 2
answered on 07 Apr 2010, 02:33 PM
You are right. Just "forward mapping" after "reverse...", select class and change control.
[I set concurrency control to "none", updates will be performed by "where Key" only]
Thank you very much!
Luca
0
IT-Als
Top achievements
Rank 1
answered on 07 Apr 2010, 02:34 PM
You're welcome and thanks for marking this as answered.
Tags
General Discussions
Asked by
Castgroup srl
Top achievements
Rank 2
Answers by
IT-Als
Top achievements
Rank 1
Castgroup srl
Top achievements
Rank 2
Share this question
or