Don't worry about sharing the performance report, I've collected enough data to analyze the issue. One more question though: are you using migrations, or a non-default database initializer?
Thanks,
David.
Thanks,
David.
FROM [dbo].[User] AS [Extent1]
INNER JOIN [dbo].[Document] AS [Extent2] ON [Extent1].[IdDocument] = [Extent2].[IdDocument]
WHERE [Extent2].[Document] = @p__linq__0 ) AS [Limit1]
LEFT OUTER JOIN [dbo].[Document] AS [Extent3] ON [Limit1].[IdDocument1] = [Extent3].[IdDocument]',N'@p__linq__0 nvarchar(max) ',@p__linq__0=N'01420276506'[Limit1].[IdUser] AS [IdUser],
[Limit1].[MobileCode] AS [MobileCode],
[Limit1].[MobileSession] AS [MobileSession],
[Limit1].[Name] AS [Name],
[Limit1].[Email] AS [Email],
[Limit1].[IdCountry] AS [IdCountry],
[Limit1].[Password] AS [Password],
[Limit1].[PasswordSalt] AS [PasswordSalt],
[Limit1].[Sex] AS [Sex],
[Limit1].[Birthday] AS [Birthday],
[Limit1].[TelephoneNumber] AS [TelephoneNumber],
[Limit1].[CellphoneNumber] AS [CellphoneNumber],
[Limit1].[Cep] AS [Cep],
[Limit1].[AcceptNewsletter] AS [AcceptNewsletter],
[Limit1].[DateCreated] AS [DateCreated],
[Limit1].[LastUpdate] AS [LastUpdate],
[Limit1].[IdAddress] AS [IdAddress],
[Limit1].[IdDocument] AS [IdDocument],
[Limit1].[IdDiscountApproval] AS [IdDiscountApproval],
[Limit1].[IsEmailValid] AS [IsEmailValid],
[Limit1].[TimeLimitConfirm] AS [TimeLimitConfirm],
[Limit1].[FacebookId] AS [FacebookId],
[Limit1].[TwitterId] AS [TwitterId],
[Limit1].[OnFacebookCreated] AS [OnFacebookCreated],
[Limit1].[OnTwitterCreated] AS [OnTwitterCreated],
[Limit1].[IdDocument1] AS [IdDocument1],
[Limit1].[IdDocumentType] AS [IdDocumentType],
[Limit1].[Document] AS [Document]
FROM ( SELECT TOP (1)
[Extent1].[IdUser] AS [IdUser],
[Extent1].[MobileCode] AS [MobileCode],
[Extent1].[MobileSession] AS [MobileSession],
[Extent1].[Name] AS [Name],
[Extent1].[Email] AS [Email],
[Extent1].[IdCountry] AS [IdCountry],
[Extent1].[Password] AS [Password],
[Extent1].[PasswordSalt] AS [PasswordSalt],
[Extent1].[Sex] AS [Sex],
[Extent1].[Birthday] AS [Birthday],
[Extent1].[TelephoneNumber] AS [TelephoneNumber],
[Extent1].[CellphoneNumber] AS [CellphoneNumber],
[Extent1].[Cep] AS [Cep],
[Extent1].[AcceptNewsletter] AS [AcceptNewsletter],
[Extent1].[DateCreated] AS [DateCreated],
[Extent1].[LastUpdate] AS [LastUpdate],
[Extent1].[IdAddress] AS [IdAddress],
[Extent1].[IdDocument] AS [IdDocument],
[Extent1].[IdDiscountApproval] AS [IdDiscountApproval],
[Extent1].[IsEmailValid] AS [IsEmailValid],
[Extent1].[TimeLimitConfirm] AS [TimeLimitConfirm],
[Extent1].[FacebookId] AS [FacebookId],
[Extent1].[TwitterId] AS [TwitterId],
[Extent1].[OnFacebookCreated] AS [OnFacebookCreated],
[Extent1].[OnTwitterCreated] AS [OnTwitterCreated],
[Extent2].[IdDocument] AS [IdDocument1],
[Extent2].[IdDocumentType] AS [IdDocumentType],
[Extent2].[Document] AS [Document]
FROM [dbo].[User] AS [Extent1]
LEFT OUTER JOIN [dbo].[Document] AS [Extent2] ON [Extent1].[IdDocument] = [Extent2].[IdDocument]
WHERE (([Extent2].[Document] = @p__linq__0) AND ( NOT ([Extent2].[Document] IS NULL OR @p__linq__0 IS NULL))) OR (([Extent2].[Document] IS NULL) AND (@p__linq__0 IS NULL))
) AS [Limit1]',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'01420276506'
our command: where u.Document.Number.Equals(document)
select u).ApplyIncludes("Document");
return query.FirstOrDefault();_____context.Configuration.UseDatabaseNullSemantics = true;
In the following expression:((x = y) AND NOT (x IS NULL OR y IS NULL)) OR (x IS NULL AND y IS NULL)
That extra 'AND NOT (x IS NULL OR y IS NULL)' part is added with the goal of avoiding returning incorrect results in the particular case in which either x or y are NULL but both aren't null at the same time and the whole comparison expression is negated in the query.
var dbEmp = zbdlcontext.Emp_Manager;
var dbCompany = zbdlcontext.Corp_CompanyInfos;
var dbFlowCode = zbdlcontext.FlowCodes;
var dbEmpPost = zbdlcontext.Emp_Post;
var query = from emps in dbEmp
join companies in dbCompany on emps.CorpGuid equals companies.CorpUserGuid
join flowCode in dbFlowCode on new { EmpGuid = emps.EmpGuid.ToString(), AreaCode = areaCode } equals new { EmpGuid = flowCode.ObjectId, AreaCode = flowCode.AreaCode } into jFlowCodes
from flowCodes in jFlowCodes.DefaultIfEmpty()
join post in dbEmpPost on emps.EmpGuid equals post.EmpGuid into jPosts
from posts in jPosts.DefaultIfEmpty()
select new tb_Emp_Manager()
{
EmpGuid = emps.EmpGuid,
AreaCode = emps.AreaCode,
FlowCode = flowCodes.FlowCode,
corpName = companies.CorpName
};
join flowCode in dbFlowCode on new { EmpGuid = emps.EmpGuid.ToString(), AreaCode = areaCode } equals new { EmpGuid = flowCode.ObjectId, AreaCode = flowCode.AreaCode } into jFlowCodes
from flowCodes in jFlowCodes.DefaultIfEmpty()