Skip to content

Instantly share code, notes, and snippets.

@MatthewDavidCampbell
Created February 12, 2015 13:27
Show Gist options
  • Save MatthewDavidCampbell/b95ae513628aee42f182 to your computer and use it in GitHub Desktop.
Save MatthewDavidCampbell/b95ae513628aee42f182 to your computer and use it in GitHub Desktop.
C# SQL Server Provider Not Creating the Correct Query
System.Data.Entity.Core.Objects.ObjectQuery`1[Charting.Models.BrandVisited])
.MergeAs(NoTracking)
.Select(Param_0 => new Dynamic-1664969929() {BrandVisited = Param_0})
.Join(
value(System.Data.Entity.Core.Objects.ObjectQuery`1[Charting.Models.BrandInfo])
.MergeAs(NoTracking)
, Outer => new Dynamic482297455() {BrandId = Outer.BrandVisited.BrandId}
, Inner => new Dynamic482297455() {BrandId = Inner.BrandId}
, (Outer, Inner) => new Dynamic-1664969929-347479675() {BrandInfo = Inner, BrandVisited = Outer.BrandVisited}
)
.Join(
value(System.Data.Entity.Core.Objects.ObjectQuery`1[Charting.Models.Occasion])
.MergeAs(NoTracking)
, Outer => new Dynamic1345382450() {RespondentId = Outer.BrandVisited.RespondentId, OccasionId = Outer.BrandVisited.OccasionId}
, Inner => new Dynamic1345382450() {RespondentId = Inner.RespondentId, OccasionId = Inner.OccasionId}
, (Outer, Inner) => new Dynamic-1664969929-347479675-1127279292() {Occasion = Inner, BrandInfo = Outer.BrandInfo, BrandVisited = Outer.BrandVisited}
)
.Join(
value(System.Data.Entity.Core.Objects.ObjectQuery`1[Charting.Models.Respondent])
.MergeAs(NoTracking),
Outer => new Dynamic-1955736974() {RespondentId = Outer.Occasion.RespondentId},
Inner => new Dynamic-1955736974() {RespondentId = Inner.RespondentId},
(Outer, Inner) => new Dynamic-1664969929-347479675-1127279292852112994() {Respondent = Inner, Occasion = Outer.Occasion, BrandInfo = Outer.BrandInfo, BrandVisited = Outer.BrandVisited}
)
.GroupBy(Param_1 => new Dynamic530482725() {Year = Param_1.Respondent.currentVisitYear, Month = Param_1.Respondent.currentVisitMonth})
.OrderBy(Param_2 => Param_2.Key.Year).ThenBy(Param_2 => Param_2.Key.Month)
.Select(Param_3 => new Dynamic1336473820() {
Measurement = (Param_3.Sum(m => Convert((Convert(m.Respondent.MWEIGHT) * Convert(m.BrandVisited.NUM_PAID)))) / Param_3.Sum(m => Convert(m.Respondent.MWEIGHT))),
Year = Param_3.Key.Year,
Month = Param_3.Key.Month,
Base = Param_3.Count(),
Days = Param_3.Select(y => Convert(y.Respondent.visitDate)).Distinct().Count()
})
SELECT
[Project3].[C2] AS [C1],
[Project3].[C3] AS [C2],
[Project3].[VISIT_DATE_YEAR] AS [VISIT_DATE_YEAR],
[Project3].[VISIT_DATE_MONTH] AS [VISIT_DATE_MONTH],
[Project3].[C1] AS [C3],
[Project3].[C4] AS [C4]
FROM ( SELECT
[Project2].[C3] AS [C1],
[Project2].[VISIT_DATE_MONTH] AS [VISIT_DATE_MONTH],
[Project2].[VISIT_DATE_YEAR] AS [VISIT_DATE_YEAR],
1 AS [C2],
[Project2].[C1] / [Project2].[C2] AS [C3],
[Project2].[C4] AS [C4]
FROM ( SELECT
[GroupBy1].[A1] AS [C1],
[GroupBy1].[A2] AS [C2],
[GroupBy1].[A3] AS [C3],
[GroupBy1].[K1] AS [VISIT_DATE_MONTH],
[GroupBy1].[K2] AS [VISIT_DATE_YEAR],
[SSQTAB1].[A1] AS [C4]
FROM ( SELECT
[Join1].[K1] AS [K1],
[Join1].[K2] AS [K2],
SUM([Join1].[A1]) AS [A1],
SUM([Join1].[A2]) AS [A2],
COUNT([Join1].[A3]) AS [A3]
FROM ( SELECT
[Extent2].[VISIT_DATE_MONTH] AS [K1],
[Extent2].[VISIT_DATE_YEAR] AS [K2],
[Extent2].[MWEIGHT] * ( CAST( [Extent1].[NUM_PAID] AS float)) AS [A1],
[Extent2].[MWEIGHT] AS [A2],
1 AS [A3]
FROM [p_Brand_Visited] AS [Extent1]
INNER JOIN [p_Respondent] AS [Extent2] ON [Extent1].[RESP_ID] = [Extent2].[RESP_ID]
) AS [Join1]
GROUP BY [K1], [K2]
) AS [GroupBy1]
OUTER APPLY
(SELECT
COUNT(1) AS [A1]
FROM ( SELECT DISTINCT
[Extent4].[VISIT_DATE] AS [VISIT_DATE]
FROM [p_Brand_Visited] AS [Extent3]
INNER JOIN [p_Respondent] AS [Extent4] ON [Extent3].[RESP_ID] = [Extent4].[RESP_ID]
WHERE (([GroupBy1].[K2] = [Extent4].[VISIT_DATE_YEAR]) OR (([GroupBy1].[K2] IS NULL) AND ([Extent4].[VISIT_DATE_YEAR] IS NULL))) AND (([GroupBy1].[K1] = [Extent4].[VISIT_DATE_MONTH]) OR (([GroupBy1].[K1] IS NULL) AND ([Extent4].[VISIT_DATE_MONTH] IS NULL)))
) AS [Distinct1]) AS [SSQTAB1]
) AS [Project2]
) AS [Project3]
ORDER BY [Project3].[VISIT_DATE_YEAR] ASC, [Project3].[VISIT_DATE_MONTH] ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment