1

While converting an SQL query below query with navigation in Entity Framework

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

I wrote the following function to populate gridview

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() is not working as it works in the SQL. I am confused how to use Distinct as I have used in SQL

Shomaail
  • 493
  • 9
  • 30
  • Please show what you tried, because it's not clear where you're stuck. I assume you tried LINQ's `join` statement. Where did you have problems? – Gert Arnold Oct 16 '17 at 13:10
  • Also, LINQ-to-SQL and Entity Framework are two different technologies. – Gert Arnold Oct 16 '17 at 13:12
  • For joining on two columns see https://stackoverflow.com/questions/38431739/linq-to-sql-left-join-on-multiple-columns – sgmoore Oct 16 '17 at 13:17
  • 1
    `context.Application_TaskLog` already returns distinct `Application_TaskLog` records and there's nothing in the query that duplicates them, so `Distinct()` doesn't make any difference. – Gert Arnold Oct 18 '17 at 08:39

1 Answers1

0

context.Application_TaskLog already returns distinct Application_TaskLog records and there's nothing in the query that duplicates them, so Distinct() doesn't make any difference

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Shomaail
  • 493
  • 9
  • 30