EDIT: Calling
var _data = context.Database.SqlQuery<InfoViewModel>(sql).FirstOrDefault();
if I ran the below sql in the sql management studio and its works without throwing any error but if I have the same query called using EF its throwing the below error message:
here is my SQL:
SELECT
FROM dbo.Clients LEFT OUTER JOIN
dbo.aspnet_Users AS c ON dbo.Clients.CollectionsAssignedTo = c.UserId
LEFT OUTER JOIN dbo.aspnet_Users AS b ON dbo.Clients.Auditors_Key = b.UserId
LEFT OUTER JOIN dbo.aspnet_Users AS a ON dbo.Clients.AcctRep = a.UserId
WHERE dbo.Clients.ClientPKID = 'ce723426-dert-4c36-980a-f5181870d0d4'
The cast to value type 'System.Guid' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type