Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. linq bug ???

linq bug ???

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhardwarehelp
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brain2cpu
    wrote on last edited by
    #1

    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?

    H 1 Reply Last reply
    0
    • B brain2cpu

      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?

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups