Puzzling Duplication in Data Binding with LINQ to Entities [modified]
-
,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 --
-
,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 --
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 -
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 111111Thanks, I'll have a check.
-
,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 --
-
Smells like a paging issue. :^)
xacc.ide
IronScheme - 1.0 beta 3 - out now!
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))I thought so too, but my GridView isn't paged, and it only shows more duplicates at one time than the paged RadGrid.
-
I thought so too, but my GridView isn't paged, and it only shows more duplicates at one time than the paged RadGrid.
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))