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. The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to GroupJoin

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to GroupJoin

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqquestion
2 Posts 2 Posters 6 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.
  • D Offline
    D Offline
    dotnet95
    wrote on last edited by
    #1

    select a.LoanNum, PromiseAmt, isnull(SUM(PdAmt), 0) as PostedAmt
    from LoanPromises a with(nolock)
    left outer join LoanPayment lp with(nolock) on a.LoanNum = lp.LoanNum and a.PromiseDt < lp.PmtPostDt
    group by a.LoanNum, PromiseAmt
    having isnull(Sum(PdAmt),0) < PromiseAmt

    Here is my linq query

    var query = from pmts in oLoan.LoanPayments
    join promise in oLoan.LoanPromiseToPays
    on new { p1 = pmts.LoanNum, p2 = pmts.PmtPostDt} equals new {LoanNum = promise.LoanNum, PmtPostDt = promise.PromiseDt } into outer
    from defaulted in outer.DefaultIfEmpty()
    group defaulted by promise.LoanNum && promise.PromiseAmt into grouped
    select new
    {
    LoanNum = grouped.Key,
    Sum = grouped.Sum(t => t.PdAmt < t.PromiseAmt),
    PmtPostDt = promise.PromiseDt ?? default(DateTime)
    }

    Richard DeemingR 1 Reply Last reply
    0
    • D dotnet95

      select a.LoanNum, PromiseAmt, isnull(SUM(PdAmt), 0) as PostedAmt
      from LoanPromises a with(nolock)
      left outer join LoanPayment lp with(nolock) on a.LoanNum = lp.LoanNum and a.PromiseDt < lp.PmtPostDt
      group by a.LoanNum, PromiseAmt
      having isnull(Sum(PdAmt),0) < PromiseAmt

      Here is my linq query

      var query = from pmts in oLoan.LoanPayments
      join promise in oLoan.LoanPromiseToPays
      on new { p1 = pmts.LoanNum, p2 = pmts.PmtPostDt} equals new {LoanNum = promise.LoanNum, PmtPostDt = promise.PromiseDt } into outer
      from defaulted in outer.DefaultIfEmpty()
      group defaulted by promise.LoanNum && promise.PromiseAmt into grouped
      select new
      {
      LoanNum = grouped.Key,
      Sum = grouped.Sum(t => t.PdAmt < t.PromiseAmt),
      PmtPostDt = promise.PromiseDt ?? default(DateTime)
      }

      Richard DeemingR Online
      Richard DeemingR Online
      Richard Deeming
      wrote on last edited by
      #2

      Try taking out the p1 = and p2 = from the LHS of your join. At the moment, you have:

      on new { p1 = ..., p2 = ...} equals new { LoanNum = ..., PmtPostDt = ... }

      The compiler has no way to map one key to the other, since the property names are different. Also, your LINQ join won't match your SQL join. The SQL has promise.PromiseDate < payment.PmtPostDt, but your LINQ query has promise.PromiseDate = payment.PmtPostDt instead.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      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