views:

223

answers:

3

I don't know how to save object with where clause. I need it to prevent saving object with range of dates overlapping on others.

public class TaskEvent { public DateTime StartDate {get;set;} public DateTime EndDate {get;set;} }

I want to check overlaping in criteria within saving operation but I don't know how.

Any ideas?

+1  A: 

You need to figure out in code which objects need saving, then save those. This is business logic and should not be pushed into persistence operations. IMO, even if NH could support that.

Tim Scott
Yes, I understand but this is not clue. I need to know how put something like criteria into where when I call session.Update(). Eg.: UPDATE TaskEvent SET ... WHERE ID = @ID { how to add here some criteria}
dario-g
+1  A: 

You can use HQL for ad hoc update queries

session.CreateQuery("UPDATE TaskEvent SET ... WHERE ID = :ID and ...")
.SetInt32("ID", ID)
//.SetDateTime("", )
//.SetDateTime("", )
.ExecuteUpdate();

or to do in a more NHibernate kind of way...fetch the required TaskEvents(where clause), update their properties, and commit the transaction.

dotjoe
A: 

One approach would be to retermine which TaskEvent objects you do not want to save in code and evict them from the ISession so that they won't be persisted.

Jamie Ide