При таком LINQ запросе
var jobData = (from cj in dc.ClientJob
where cj.Id == jobId
from q in dc.Quote
where q.ClientJob_id == cj.Id
from qd in dc.QuoteDocument
where qd.Quote_id == q.Id
let Client = dc.CustomerBase.FirstOrDefault(_ => _.Id == cj.Client_id)
let QuoteDocument = dc.StoredFile.FirstOrDefault(_ => _.Id == qd.File_id)
let QuoteBid = dc.QuoteBid.FirstOrDefault(_ => _.Quote_id == q.Id)
select new
{
FabricatorId = QuoteBid.Fabricator_id,
ClientName = Client.Name,
ClientPhone = Client.Phone,
QuoteDocumentProviderRelativePath = QuoteDocument.ProviderRelativePath
}).SingleOrDefault();
Создается такой запрос
declare @jobId int = 10
SELECT TOP (2)
[t2].[Fabricator_id] as [Fabricator_id1],
[t2].[c1] as [c11],
[t4].[Name] as [Name1],
[t4].[Phone] as [Phone1],
[t6].[ProviderRelativePath] as [ProviderRelativePath1]
FROM
[dbo].[ClientJob] [t7]
OUTER APPLY (
SELECT TOP (1)
[t1].[Fabricator_id],
1 as [c1]
FROM
[dbo].[QuoteBid] [t1]
WHERE
[t1].[Quote_id] = [t8].[Id]
) [t2]
OUTER APPLY (
SELECT TOP (1)
[t3].[Name],
1 as [c2],
[t3].[Phone]
FROM
[dbo].[CustomerBase] [t3]
WHERE
[t3].[Id] = [t7].[Client_id]
) [t4]
OUTER APPLY (
SELECT TOP (1)
[t5].[ProviderRelativePath],
1 as [c3]
FROM
[dbo].[StoredFile] [t5]
WHERE
[t5].[Id] = [t9].[File_id]
) [t6],
[dbo].[Quote] [t8],
[dbo].[QuoteDocument] [t9]
WHERE
[t7].[Id] = @jobId AND [t8].[ClientJob_id] = [t7].[Id] AND
[t9].[Quote_id] = [t8].[Id]
В котором такая ошибка
Msg 4104, Level 16, State 1, Line 21
The multi-part identifier "t8.Id" could not be bound.
Msg 4104, Level 16, State 1, Line 40
The multi-part identifier "t9.File_id" could not be bound.