0
IQueryable<CustomObject> obj = (from table in db.TableName
                                                        orderby table.ObjectId descending
                                                        select
                                                            new CustomObject
                                                            {
                                                                 //Properties mapped here
                                                            }).Skip((pageNumber - 1) * pageSize).Take(pageSize);

The above is a stripped down version of the query I am running. It is missing about 10 joins and then just the bulk mapping of the object, which I have stripped out for confidentiality.

When run:
- pageNumber = 1
- pageSize = 500

table.ObjectId is a PK and so assumable to be unique

The query returns 500 objects into the IQueryable object, however instead of these 500 entries being unique I appear to get about 19 rows from the database duplicated across the 500 rows.

Is there an obvious reason as to why as I cannot find anything on Google regarding it.

Results in the object fit the following kind of pattern:

DBRow1
DBRow1
DBRow1
DBRow1
DBRow1
DBRow1
DBRow1
DBRow1
DBRow1
DBRow1
DBRow2
DBRow2
DBRow2
DBRow2
DBRow2
DBRow2
DBRow2
DBRow2
DBRow2
DBRow3
etc..

Edited by Mike Askew

1
Contributor
1
Reply
9
Views
3 Years
Discussion Span
Last Post by Mike Askew
0

The issue turned out to be my misunderstanding of how joins work with .Net and LINQ.

The duplicate rows were the rows joined to the original table. To remove them I had to implement a custom IEqualityComparer to provide to the .Distinct() call.

I can pad out the explanation a bit if anyone needs it.

Edited by Mike Askew

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.