This one does not work:
var queryEH = from eh in entity.EmployeesHires where eh.ParentKey == item.PPYKey select eh;
foreach (var itemEH in queryEH)
{
var query = (from el in entity.EmployeeLeaves where el.HireID == itemEH.ID select el.Duration).Sum();
}
whereas this one does:
var queryEH = from eh in entity.EmployeesHires where eh.ParentKey == item.PPYKey select eh;
foreach (var itemEH in queryEH)
{
var query = (from el in entity.EmployeeLeaves where el.HireID == 125 select el.Duration).Sum();
}
The exception on the first one is:
The cast to value type 'System.Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.