Update using primary key only

Thread is closed for posting
6 posts, 1 answers
  1. Castgroup srl
    Castgroup srl avatar
    8 posts
    Member since:
    Jun 2009

    Posted 07 Apr 2010 Link to this post

    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
  2. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 07 Apr 2010 Link to this post

    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
  3. Castgroup srl
    Castgroup srl avatar
    8 posts
    Member since:
    Jun 2009

    Posted 07 Apr 2010 Link to this post

    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



  4. Answer
    IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 07 Apr 2010 Link to this post

    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
  5. Castgroup srl
    Castgroup srl avatar
    8 posts
    Member since:
    Jun 2009

    Posted 07 Apr 2010 Link to this post

    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
  6. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 07 Apr 2010 Link to this post

    You're welcome and thanks for marking this as answered.
Back to Top