У меня есть запрос VB.Net Linq to Entities, который возвращает данные обратно из SQL Server 2005. Если я копирую запрос в LinqPad, он работает как положено, но когда я пытаюсь выполнить код, он возвращает все значения, равные 1.
Единственное, что изменяется, - это значения дат, которые в LQPAD выводятся в качестве параметров в VB.
Есть идеи, что не так?
Параметры даты из ViewModel приведены ниже и должны представлять 1 января 2011 г. -> 1 февраля 2011 г.
? STARTDATE
"# 1/1/2011 #"
?Дата окончания
"# 2/1/2011 #"
Public Function GetPLMNewPartCounts(ByVal startDate As Date, ByVal endDate As Date) As IEnumerable(Of NewPartsCounts)
Return From i In ObjectContext.tblEngineeringDashboard_ItemList
Join t In ObjectContext.tblTimes On t.ID Equals i.TimeID
Join b In ObjectContext.tblEngineeringDashboard_Business On b.ID Equals i.BusinessID
Where t.Period >= startDate And t.Period <= endDate
Group b By Key = b.BusinessUnit Into Group
Select New NewPartsCounts With {.BusinessUnit = Key,
.NewPartsCount = Group.Select(Function(c) c.BusinessUnit).Distinct().Count()}
End Function
TSQL из профилировщика SQL
exec sp_executesql N'SELECT
1 AS [C1],
[Project4].[BusinessUnit] AS [BusinessUnit],
[Project4].[C1] AS [C2]
FROM ( SELECT
[Project2].[BusinessUnit] AS [BusinessUnit],
(SELECT
COUNT(1) AS [A1]
FROM ( SELECT DISTINCT
[Extent6].[BusinessUnit] AS [BusinessUnit]
FROM [dbo].[tblEngineeringDashboard_ItemList] AS [Extent4]
INNER JOIN [dbo].[tblTime] AS [Extent5] ON [Extent4].[TimeID] = [Extent5].[ID]
INNER JOIN [dbo].[tblEngineeringDashboard_Business] AS [Extent6] ON [Extent4].[BusinessID] = [Extent6].[ID]
WHERE ([Extent5].[Period] >= @p__linq__0) AND ([Extent5].[Period] <= @p__linq__1) AND ([Project2].[BusinessUnit] = [Extent6].[BusinessUnit])
) AS [Distinct2]) AS [C1]
FROM ( SELECT
[Distinct1].[BusinessUnit] AS [BusinessUnit]
FROM ( SELECT DISTINCT
[Extent3].[BusinessUnit] AS [BusinessUnit]
FROM [dbo].[tblEngineeringDashboard_ItemList] AS [Extent1]
INNER JOIN [dbo].[tblTime] AS [Extent2] ON [Extent1].[TimeID] = [Extent2].[ID]
INNER JOIN [dbo].[tblEngineeringDashboard_Business] AS [Extent3] ON [Extent1].[BusinessID] = [Extent3].[ID]
WHERE ([Extent2].[Period] >= @p__linq__0) AND ([Extent2].[Period] <= @p__linq__1)
) AS [Distinct1]
) AS [Project2]
) AS [Project4]',N'@p__linq__0 datetime,@p__linq__1 datetime',@p__linq__0='2011-01-01 00:00:00:000',@p__linq__1='2011-02-01 00:00:00:000'