在实体框架中使用导航转换下面的 SQL 查询时
SELECT DISTINCT
a.ApplicationID, eA.EmployeeID AS AppID, eA.EmailID AS AppEmail,
eA.Title + eA.Name AS Applicant, eR.EmployeeID, eR.Title + eR.Name
AS Employee, eR.EmailID AS Email, r.Title AS Role, r.RoleID, t .Title AS
Task, t .TaskID, d .ShortName AS AppDeptSN, a.Reminders, '' AS SubTaskID
FROM
dbo.Application_TaskLog AS a INNER JOIN
dbo.Task AS t ON t .TaskID = a.TaskID INNER JOIN
dbo.Role AS r ON r.RoleID = t .RoleID INNER JOIN
dbo.Application_Role AS ar ON ar.ApplicationID = a.ApplicationID AND
ar.RoleID = t .RoleID INNER JOIN
dbo.Employee AS eR ON eR.EmployeeID = ar.EmployeeID INNER JOIN
dbo.Application AS app ON app.ApplicationID = a.ApplicationID INNER JOIN
dbo.Employee AS eA ON eA.EmployeeID = app.EmployeeID LEFT OUTER JOIN
dbo.Departments AS d ON eA.DepartmentID = d .DepartmentID
我编写了以下函数来填充网格视图
public List<Application_TaskLog> GetAppTaskLogDistinct(int appID)
{
var context = new FPSDB_newEntities();
var data = (from atl in context.Application_TaskLog
where atl.ApplicationID == appID
&& !atl.Application.ApplicationClosed && !atl.Completed
select atl).Distinct().ToList();
return data;
}
Distinct() 在 SQL 中不起作用。我很困惑如何使用我在SQL中使用的Distinct
context.Application_TaskLog
已经返回不同的Application_TaskLog
记录,并且查询中没有任何内容可以重复它们,因此Distinct()
没有任何区别