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. Database & SysAdmin
  3. Database
  4. SQL Linq, Joins, returns 1st record over and over

SQL Linq, Joins, returns 1st record over and over

Scheduled Pinned Locked Moved Database
databasecsharplinqsalesregex
2 Posts 1 Posters 0 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
    jkirkerx
    wrote on last edited by
    #1

    So I wrote this expression, when I use the joins, I get the first record in the amount of row count. But when I remove the joins, I get all the records. could this be an error in my Database, in which I have to change the ID column names to make a match, or am I just missing something in my expression? So this works

    pResults = _
    (
    From ca In context.Customer_Accounts
    Where ca.DateOpened >= DbFunctions.AddDays(Today, -1)
    Order By ca.DateOpened Descending
    Select New accountIndex With
    {
    .ID = ca.ID,
    .firstName = ca.FirstName,
    .lastName = ca.LastName,
    .accountName = ca.AccountName,
    .secure_EmailAdddress = ca.EmailAddress,
    .dateOpened = ca.DateOpened
    }
    ).AsEnumerable()

    This return the first row multiple times

    pResults = _
    (
    From ca In context.Customer_Accounts
    Join ba In context.CUstomer_BillingAddress On ba.CustomerID Equals ca.ID
    Join sa In context.Customer_ShippingAddress On sa.CustomerID Equals ca.ID
    Where ca.DateOpened >= DbFunctions.AddDays(Today, -7)
    Order By ca.DateOpened Descending
    Select New accountIndex With
    {
    .ID = ca.ID,
    .firstName = ca.FirstName,
    .lastName = ca.LastName,
    .accountName = ca.AccountName,
    .secure_EmailAdddress = ca.EmailAddress,
    .dateOpened = ca.DateOpened,
    .billing_FirstName = If(ba.Name1 Is Nothing, Nothing, ba.Name1),
    .billing_LastName = If(ba.Name2 Is Nothing, Nothing, ba.Name2),
    .shipping_FirstName = If(sa.Name1 Is Nothing, Nothing, sa.Name1),
    .shipping_LastName = If(sa.Name2 Is Nothing, Nothing, sa.Name2)
    }
    ).AsEnumerable()

    J 1 Reply Last reply
    0
    • J jkirkerx

      So I wrote this expression, when I use the joins, I get the first record in the amount of row count. But when I remove the joins, I get all the records. could this be an error in my Database, in which I have to change the ID column names to make a match, or am I just missing something in my expression? So this works

      pResults = _
      (
      From ca In context.Customer_Accounts
      Where ca.DateOpened >= DbFunctions.AddDays(Today, -1)
      Order By ca.DateOpened Descending
      Select New accountIndex With
      {
      .ID = ca.ID,
      .firstName = ca.FirstName,
      .lastName = ca.LastName,
      .accountName = ca.AccountName,
      .secure_EmailAdddress = ca.EmailAddress,
      .dateOpened = ca.DateOpened
      }
      ).AsEnumerable()

      This return the first row multiple times

      pResults = _
      (
      From ca In context.Customer_Accounts
      Join ba In context.CUstomer_BillingAddress On ba.CustomerID Equals ca.ID
      Join sa In context.Customer_ShippingAddress On sa.CustomerID Equals ca.ID
      Where ca.DateOpened >= DbFunctions.AddDays(Today, -7)
      Order By ca.DateOpened Descending
      Select New accountIndex With
      {
      .ID = ca.ID,
      .firstName = ca.FirstName,
      .lastName = ca.LastName,
      .accountName = ca.AccountName,
      .secure_EmailAdddress = ca.EmailAddress,
      .dateOpened = ca.DateOpened,
      .billing_FirstName = If(ba.Name1 Is Nothing, Nothing, ba.Name1),
      .billing_LastName = If(ba.Name2 Is Nothing, Nothing, ba.Name2),
      .shipping_FirstName = If(sa.Name1 Is Nothing, Nothing, sa.Name1),
      .shipping_LastName = If(sa.Name2 Is Nothing, Nothing, sa.Name2)
      }
      ).AsEnumerable()

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

      I had multiple billing and shipping addresses, in the join. So I need to redesign that feature.

      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