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. Cannot get LINQ statement to work

Cannot get LINQ statement to work

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelpquestion
4 Posts 3 Posters 4 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.
  • J Offline
    J Offline
    jmonfu
    wrote on last edited by
    #1

    Dear All I have the following linq statement var IncompleteMonitoringReportsCount = (from l in Logons join con in Consultants on l.IDCounter equals con.IDContact join tb in Topic on con.CountryCode equals tb.CountryCode join tx in TopicText on new {tb.IDTopic, tb.BaseLanguageCode} equals new {tx.IDTopic, tx.LanguageCode} select l).Count(); What Am I doing wrong in this query? Thanks for your help and time

    J S 2 Replies Last reply
    0
    • J jmonfu

      Dear All I have the following linq statement var IncompleteMonitoringReportsCount = (from l in Logons join con in Consultants on l.IDCounter equals con.IDContact join tb in Topic on con.CountryCode equals tb.CountryCode join tx in TopicText on new {tb.IDTopic, tb.BaseLanguageCode} equals new {tx.IDTopic, tx.LanguageCode} select l).Count(); What Am I doing wrong in this query? Thanks for your help and time

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      This is what you're doing wrong:

      jmonfu wrote:

      new {tb.IDTopic, tb.BaseLanguageCode} equals new {tx.IDTopic, tx.LanguageCode}

      The two new statements will generate totally different objects which are not equal. Why cant you just do:

      join tx in TopicText on (tb.IDTopic equals tx.IDTopic and tb.BaseLanguageCode equals tx.LanguageCode)

      (untested - give it a try!)

      S 1 Reply Last reply
      0
      • J jmonfu

        Dear All I have the following linq statement var IncompleteMonitoringReportsCount = (from l in Logons join con in Consultants on l.IDCounter equals con.IDContact join tb in Topic on con.CountryCode equals tb.CountryCode join tx in TopicText on new {tb.IDTopic, tb.BaseLanguageCode} equals new {tx.IDTopic, tx.LanguageCode} select l).Count(); What Am I doing wrong in this query? Thanks for your help and time

        S Offline
        S Offline
        Sir Dot Net
        wrote on last edited by
        #3

        Try this: from l in Logons join con in Consultants on l.IDCounter equals con.IDContact join tb in Topic on con.CountryCode equals tb.CountryCode from tx in TopicText where tx.IDTopic == tb.IDTopic && tx.LanguageCode == tb.BaseLanguageCode select l I think the problem is that the LINQ parser is looking at the equality of two anonymous objects (your 'new {..}'s) via GetHashCode, and not the properties of those declared anonymous objects.

        1 Reply Last reply
        0
        • J J4amieC

          This is what you're doing wrong:

          jmonfu wrote:

          new {tb.IDTopic, tb.BaseLanguageCode} equals new {tx.IDTopic, tx.LanguageCode}

          The two new statements will generate totally different objects which are not equal. Why cant you just do:

          join tx in TopicText on (tb.IDTopic equals tx.IDTopic and tb.BaseLanguageCode equals tx.LanguageCode)

          (untested - give it a try!)

          S Offline
          S Offline
          Sir Dot Net
          wrote on last edited by
          #4

          As far as I know, the LINQ 'join' can only use one equality comparer. For complex joins you should use multiple 'from's. Example: from n in Logins from z in Topics where n.ID==z.ID && n != null select n

          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