I am on framework 4.0. This is a WPF application, on sql server CE, which is a little limiting.
I have an entity that looks like this:
public class TimeEvent
{
public int Id
{get; set;}
public DateTime EventDate
{get; set;}
public bool CheckIn
{get; set;}
}
I have two types of events, one for checkin (CheckIn is true) and one for checkout (CheckIn is false). Each of the events happens once per day.
What I want to do using linq to entities, is to end up with a set of objects like this:
public class Diff
{
public DateTime Date //The date of both events
{get; set;}
public DateTime CheckInTime //Time of first event
{get; set;}
public DateTime CheckOutTime //Time of second event
{get; set;}
public int Hours //Difference in hours.
{ get { return (CheckOutTime - CheckInTime).Hours;}
}
There are validation rules in place so no more than one event of each type can happen in one day.
I tried using the aggregate function, but I’m really not getting anywhere.
Thank you!
Group your time events by
EventDatedate part. To get that you need to useEntityFunctions.TruncateTimemethod (simpleEventDate.Datewill not work with Entity Framework).Also you can calculate time difference on server side with
EntityFunctions.DiffHours(checkOut, checkIn).