Monthly Archives: April 2013

LINQ to Entities Date Calculations

If you need to perform a DateDiff between 2 dates in your LINQ query:

var results = from r in db.Results
where r.Extra2 == id && r.CampaignID == 64
select new
{
Phone = r.Phone,
Pickup = r.PickUp,
Duration = EntityFunctions.DiffSeconds(r.PickUp,r.HangUp),
AnswerType = r.AnswerType

};

Notice the line - EntityFunctions.DiffSeconds(r.PickUp,r.HangUp)