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. Puzzling Duplication in Data Binding with LINQ to Entities [modified]

Puzzling Duplication in Data Binding with LINQ to Entities [modified]

Scheduled Pinned Locked Moved LINQ
csharpdatabaseasp-netsql-serverwpf
6 Posts 3 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.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    ,I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView to the results of the following LINQ to entities query. In both cases the grids contain the correct number of rows, but the data from only the first handful of rows is duplicated in all the other rows. I'm directly assigning the return value from this code the the DataSource property on the grids.         return from dp in dents.DirectoryPersonEntrySet*                where                     dp.LastName.StartsWith(searchTerm) ||                     dp.Extension.StartsWith(searchTerm)                orderby dp.LastName, dp.Extension                select dp; * Such fun naming abstract things, sigh. Example, the query, when run in LinqPad, and under translation in SQL Server, returns 65 unique records, but the ASP.NET GridView repeats the first records all over the 65 rows it renders: Raaff,Andre,7958
    Rabie,Hermien,8286
    Rabodiba,Kgaugelo,3444
    Rabie,Hermien,8286
    Raaff,Andre,7958
    Radebe,Andries,6438
    Rabit Lab,6648
    Rabie,Hermien,8286


    Last modified: 15hrs 59mins after originally posted --

    H L 2 Replies Last reply
    0
    • B Brady Kelly

      ,I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView to the results of the following LINQ to entities query. In both cases the grids contain the correct number of rows, but the data from only the first handful of rows is duplicated in all the other rows. I'm directly assigning the return value from this code the the DataSource property on the grids.         return from dp in dents.DirectoryPersonEntrySet*                where                     dp.LastName.StartsWith(searchTerm) ||                     dp.Extension.StartsWith(searchTerm)                orderby dp.LastName, dp.Extension                select dp; * Such fun naming abstract things, sigh. Example, the query, when run in LinqPad, and under translation in SQL Server, returns 65 unique records, but the ASP.NET GridView repeats the first records all over the 65 rows it renders: Raaff,Andre,7958
      Rabie,Hermien,8286
      Rabodiba,Kgaugelo,3444
      Rabie,Hermien,8286
      Raaff,Andre,7958
      Radebe,Andries,6438
      Rabit Lab,6648
      Rabie,Hermien,8286


      Last modified: 15hrs 59mins after originally posted --

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

      Hmmmm... thats a very strange problem you got there Brady Just by reading your code i cant immeadiatly see anything wrong... I've seen very weird things happen if you send linq query results round as parameters or return values. Maybe try to do this

      var result = from dp in dents.DirectoryPersonEntrySet*
      where
      dp.LastName.StartsWith(searchTerm) ||
      dp.Extension.StartsWith(searchTerm)
      orderby dp.LastName, dp.Extension
      select dp;

      then put a line break after the query is executed. Hover your mouse over the var result and you should be able to see the contents returned by the query in the debugger. If all is well, why not try to .ToList() the query result and bind the resulting list to your grid? This has solved some troubles for me in the past.

      Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 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

      B 1 Reply Last reply
      0
      • H Harvey Saayman

        Hmmmm... thats a very strange problem you got there Brady Just by reading your code i cant immeadiatly see anything wrong... I've seen very weird things happen if you send linq query results round as parameters or return values. Maybe try to do this

        var result = from dp in dents.DirectoryPersonEntrySet*
        where
        dp.LastName.StartsWith(searchTerm) ||
        dp.Extension.StartsWith(searchTerm)
        orderby dp.LastName, dp.Extension
        select dp;

        then put a line break after the query is executed. Hover your mouse over the var result and you should be able to see the contents returned by the query in the debugger. If all is well, why not try to .ToList() the query result and bind the resulting list to your grid? This has solved some troubles for me in the past.

        Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 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

        B Offline
        B Offline
        Brady Kelly
        wrote on last edited by
        #3

        Thanks, I'll have a check.

        1 Reply Last reply
        0
        • B Brady Kelly

          ,I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView to the results of the following LINQ to entities query. In both cases the grids contain the correct number of rows, but the data from only the first handful of rows is duplicated in all the other rows. I'm directly assigning the return value from this code the the DataSource property on the grids.         return from dp in dents.DirectoryPersonEntrySet*                where                     dp.LastName.StartsWith(searchTerm) ||                     dp.Extension.StartsWith(searchTerm)                orderby dp.LastName, dp.Extension                select dp; * Such fun naming abstract things, sigh. Example, the query, when run in LinqPad, and under translation in SQL Server, returns 65 unique records, but the ASP.NET GridView repeats the first records all over the 65 rows it renders: Raaff,Andre,7958
          Rabie,Hermien,8286
          Rabodiba,Kgaugelo,3444
          Rabie,Hermien,8286
          Raaff,Andre,7958
          Radebe,Andries,6438
          Rabit Lab,6648
          Rabie,Hermien,8286


          Last modified: 15hrs 59mins after originally posted --

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Smells like a paging issue. :^)

          xacc.ide
          IronScheme - 1.0 beta 3 - out now!
          ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

          B 1 Reply Last reply
          0
          • L leppie

            Smells like a paging issue. :^)

            xacc.ide
            IronScheme - 1.0 beta 3 - out now!
            ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

            B Offline
            B Offline
            Brady Kelly
            wrote on last edited by
            #5

            I thought so too, but my GridView isn't paged, and it only shows more duplicates at one time than the paged RadGrid.

            L 1 Reply Last reply
            0
            • B Brady Kelly

              I thought so too, but my GridView isn't paged, and it only shows more duplicates at one time than the paged RadGrid.

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              Are you binding the query directly to the grid's DataSource? Try using an intermediary datasource like a BindingList or some other DataSource (I cant recall what they are called in ASP.NET).

              xacc.ide
              IronScheme - 1.0 beta 3 - out now!
              ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

              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