Reputation: 17
got 3 classes,
public calss Employee
{
public int ID { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public int Age { get; set; }
}
public class Sale
{
public int EmpID { get; set; }
public DateTime Date { get; set; }
public int Amount { get; set; }
}
and DB class which initiate a list of employees and sales and contain methods involving LINQ queries:
one of the methods, need to get a year and bring me back all the employees made a sale that year , now at the last Select I want to get from the joined list only the employee object without putting the properties myself, and ofc creating a distinct so I won't have duplicates, here where I got so far, I'd love for some help, because I'm getting error notifications:
public List<Employee> GetEmployeesMadeSale(int year)
{
var emploSales =
Employees.Join(
Sales,
e => e.ID, //empID = e.ID, Amount = s.Amount
s => s.EmpID,
(e, s) => new { Emplo = e, Year = s.Date.Year })
.Where(es => es.Year == year)
.Select(es => new Employee() = es.Emplo)
.ToList();
//return emploSales
}
Upvotes: 1
Views: 151
Reputation: 11277
The problem is your Select
.Select(es => new Employee() = es.Emplo)
Try doing this instead
.Select(es => es.Emplo)
Upvotes: 1