linq bug ???
-
Hi all, I have two expressions: var x = (from e in Program.DB.Events group e by e.Event_type_id into eg orderby eg.Count() descending select eg.Key).First(); var y = (from et in Program.DB.Event_types where et.Id == (from e in Program.DB.Events group e by e.Event_type_id into eg orderby eg.Count() descending select eg.Key).First() select et.Id).Single(); the first result (x) is ok but when using the same expression embedded in the second a wrong result came up. And here are the generated select statements from the log: SELECT TOP (1) [t1].[event_type_id] FROM ( SELECT COUNT(*) AS [value], [t0].[event_type_id] FROM [events] AS [t0] GROUP BY [t0].[event_type_id] ) AS [t1] ORDER BY [t1].[value] DESC -- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.30729.1 SELECT [t0].[id] FROM [event_types] AS [t0] OUTER APPLY ( SELECT TOP (1) [t2].[event_type_id] FROM ( SELECT [t1].[event_type_id] FROM [events] AS [t1] GROUP BY [t1].[event_type_id] ) AS [t2] ) AS [t3] WHERE [t0].[id] = [t3].[event_type_id] -- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.30729.1 The reason of the wrong result is the missing "order by" from the second select. What's wrong here?
-
Hi all, I have two expressions: var x = (from e in Program.DB.Events group e by e.Event_type_id into eg orderby eg.Count() descending select eg.Key).First(); var y = (from et in Program.DB.Event_types where et.Id == (from e in Program.DB.Events group e by e.Event_type_id into eg orderby eg.Count() descending select eg.Key).First() select et.Id).Single(); the first result (x) is ok but when using the same expression embedded in the second a wrong result came up. And here are the generated select statements from the log: SELECT TOP (1) [t1].[event_type_id] FROM ( SELECT COUNT(*) AS [value], [t0].[event_type_id] FROM [events] AS [t0] GROUP BY [t0].[event_type_id] ) AS [t1] ORDER BY [t1].[value] DESC -- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.30729.1 SELECT [t0].[id] FROM [event_types] AS [t0] OUTER APPLY ( SELECT TOP (1) [t2].[event_type_id] FROM ( SELECT [t1].[event_type_id] FROM [events] AS [t1] GROUP BY [t1].[event_type_id] ) AS [t2] ) AS [t3] WHERE [t0].[id] = [t3].[event_type_id] -- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.30729.1 The reason of the wrong result is the missing "order by" from the second select. What's wrong here?
please use pre tags when posting code... That way it might even get read!
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111