How do I add additional criteria to my update command using NHibernate? -


I have a situation where the message table has the primary key (ID) and the foreign key (site). Any site can create a message record, but only the site that has created the record can update it. The problem is that by default this ID and no will be updated based on ID and site. I want to take the primary key to ID / site to mix mixed / mixed ID and original SQL; However, I was thinking that there is no way to add additional update criteria.

For example, this is what you get by default:

 Public Zero Message Update (Message A Message) {using (session, session = session. OpenSession) Using (ITR Generation Trance = Session. Beneficiation ()) {session.Update (a message); Trans.Commit (); }} 

So how can I do this in NHibernate without creating a composite ID or without using the basic SQL:

Set message message MessageStatus = 2 where id =? And site =? You can not do this directly in NHibernate, but you can change your update method like this:

  Public Zero Message Update (Message A Message, String Current Site) {if (a message. Site! = Current site) {new exception ("meaningful error message"); } (Using anation session = sessionfire.options ()) (ITR generation tense = session .bnfenestation ()) {session.Update (a message); Trans.Commit (); }}  

Assuming the site is a property of a string and a message. Also, if you generate an exception, then you want to wrap up your transaction..we want to wrap up our transactions. Roll the transaction and rollback roll.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -