I have situation where a Message table has a primary key (Id) and a foreign key (Site). Any site can create a message record, but only the site that created the record can update it. The problem is that by default it will be updated based upon Id and not Id and Site. I could change the primary key to be a composite/compound id consisting of the id and site OR resort to Native SQL; however, I was wondering if there is a way to add additional Update criteria.
For example, this is what you get by default:
public void MessageUpdate(Message oneMessage) { using(ISession session = SessionFactory.OpenSession()) using(ITransaction trans = session.BeginTransaction()) { session.Update(oneMessage); trans.Commit(); } }
So how do I do this in NHibernate without creating a compound id or using Native SQL:
Update MessageTable set MessageStatus = 2 where Id = ? and Site = ?;