Hi there,
here is my latest problem - I hope anyone can help me - thx a lot :) :
I made a class called 'Employee' :
Code:
class Employee {
...
public virtual ISet<HolidayTime> holidayTimes {get;set;}
}
As you can see, an employee may also have holiday - and so I need another class calles 'HolidayTime' :
Code:
class HolidayTime {
public virtual DateTime from;
public virtual DateTime until;
}
That's it so far. Each employee can have several periods of time when he is not available.
What I tried is to get all employees from database, which are not in holiday today.
So I tried sth. like this:
Code:
ICriteria criteria = session.CreateCriteria<Employee>();
criteria = criteria.CreateAlias("HolidayTime", "times");
DateTime today = DateTime.Today;
Disjunction dis = Expression.Disjunction();
dis.Add(Expression.Lt("times.until", today));
dis.Add(Expression.Gt("times.from", today));
criteria.Add(dis);
IList<Employee> myList=criteria.SetResultTransformer(new DistinctRootEntityResultTransformer()).List<Employee>();
Now lets say today's is 10/09/2011 (mm/dd/yyyy).
Our employee is on holiday from 10/09/2011 until 10/20/2011.
If I start my search, this employee won't be found. Great - that is want I wanted.
BUT: Now i add another holiday period: from 10/01/2011 until 10/08/2011.
So now we have one time period which is valid for my search and one which is not. The problem is, that my search now gives out that employee, but as you can see: that employee is in holiday today :)
What have I done wrong?
Thanks for you help.
Yours
DataDummy