我有一个如下模型:
public class Employee
{
public Employee()
{
TimeCards = new List<TimeCard>();
}
public int Id { get; set; }
public string Name { get; set; }
public DateTime HireDate { get; set; }
public virtual ICollection<TimeCard> TimeCards { get; set; }
}
public class Manager : Employee
{
public bool HasCompanyCar { get; set; }
}
public class Developer : Employee
{
public string MainProgrammingLanguage { get; set; }
}
(如果它很重要,我正在使用这个基础设施)。
我需要的是让所有不是经理的员工。只有一个 OfType 扩展方法。我需要的是 NotOfType。
var employees = unitOfWork.Employees
.FindAll()
.NotOfType<Manager>(); //or something similar
var cards = unitOfWork.TimeCards.FindAll();
var query = from e in employees
from tc in cards
where tc.Employee.Id == e.Id && e.Name.StartsWith("C")
select tc;
题外话:继承是这种情况的正确选择吗?你如何建模?我只是觉得继承导致我走错了路。