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..

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.