Reputation: 751
I have the following 2 functions + 1 in progress:
public static IEnumerable<LockedDate> GetAllByEmployee(int employeeID)
{
var v = LockedDates.GetAll();
return from p in v where p.EmployeeID == employeeID select p;
}
public static IEnumerable<LockedDate> GetAllByCompany()
{
var v = LockedDates.GetAll();
return from p in v where p.EmployeeID == null select p;
}
public static List<LockedDate> GetAllForEmployee(int employeeID)
{
var empList = GetAllByEmployee(employeeID);
var compList = GetAllByCompany();
//What do???
return from p in empList and from q in compList where p and q are not duplicate . toList()
}
These use LINQ-SQL.
A LockedDate has a Date and an IsYearly bool. If IsYearly is true then the year should not be considered. Time should never be considered.
I now need a function that will include all the LockedDates that the employee has and the company ones into one list, without any duplicates. So if IsYearly && dd/mm are == or !IsYearly && dd/mm/yyyy are == then there is a duplicate. What might be an efficient, non-naive way of doing this?
Thanks
Upvotes: 1
Views: 85
Reputation: 125630
var yearly = source.Where(p => p.IsYearly)
.GroupBy(p => new { Month = p.Date.Month, Day = p.Date.Day })
.Select(g => g.First());
var nonYearly = source.Where(p => !p.IsYearly)
.GroupBy(p => p.Date.Date)
.Select(g => g.First());
return yearly.Union(nonYearly).ToList();
source
could be done easily by Union
method:
var source = GetAllByEmployee(employeeID).Union(GetAllByCompany());
Upvotes: 1
Reputation: 709
cant you do this
var v = LockedDates.GetAll();
return from p in v where p.EmployeeID == null || p.EmployeeID == employeeID select p;
Upvotes: 0