NHibernate - how to persist an object with a where clause
I don't know how to store an object with a where clause. I need this to prevent the object from being saved with a date range overlapping on others.
public class TaskEvent
{
public DateTime StartDate {get;set;}
public DateTime EndDate {get;set;}
}
I want to check if the criteria match in a save operation, but I don't know how.
Any ideas?
0
source to share
3 answers
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 do it in a more NHibernate way ... get the required TaskEvents (where clause), update their properties and commit the transaction.
+1
source to share