编辑: 调用
var _data = context.Database.SqlQuery<InfoViewModel>(sql).FirstOrDefault();
如果我在SQL Management Studio中运行下面的SQL语句,而且它没有抛出任何错误,但是如果我使用EF调用相同的查询,它会抛出以下错误消息:
这里是我的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'
由于实例化的值为null,将其转换为值类型'System.Guid'时失败。结果类型的泛型参数或查询必须使用可为空类型。