Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:21:40+00:00 2026-05-27T22:21:40+00:00

I am trying to remove the duplicates from a list I binding to a

  • 0

I am trying to remove the duplicates from a list I binding to a gridview. However no matter what I do, the duplicates remain.

The variable lol, were added for testing the Distinct, but it didn’t work.
Current code:

GWportalDataContext db = new GWportalDataContext();
    DeliveryTimeRepository dltRep = new DeliveryTimeRepository();

    var query = from o in db.Orders
                join y in db.OrderLines on o.OrderID equals y.OrderID
                join x in db.Products on y.ItemNumber equals x.ItemNumber
                where o.AccountNumber == AppSession.CurrentLoginTicket.AccountNumber
                select new
                {
                    o.OrderID,
                    o.AxaptaSalesId,
                    y.ItemNumber,
                    x.Name,
                    x.ProductFormatName,
                    y.Quantity,
                    y.Price,
                    Status = dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).Substring(0, dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).LastIndexOf("|")),
                    Levering = dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).Substring(dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).LastIndexOf("|")).Replace("|", "")
                };

    var query2 = from o in db.AxSales
                 join y in db.AxSaleLines on o.SalesId equals y.SalesId
                 join x in db.Products on y.ItemNumber equals x.ItemNumber
                 where o.AccountNumber == AppSession.CurrentLoginTicket.AccountNumber
                 select new
                 {
                     OrderID = o.SalesId,
                     AxaptaSalesId = o.SalesId,
                     y.ItemNumber,
                     x.Name,
                     x.ProductFormatName,
                     y.Quantity,
                     Price = y.SalesPrice,
                     Status = dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).Substring(0, dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).LastIndexOf("|")),
                     Levering = dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).Substring(dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).LastIndexOf("|")).Replace("|", "")
                 };

    //Query 1 start
    var dataToList = query.ToList();
    List<object> deletedItems = dataToList.Where(item => orderDeleted(item.OrderID, item.AxaptaSalesId)).Cast<object>().ToList();
    var datatoGrid = dataToList.Except(deletedItems);
    // Query 1 end

    //Query 2 start
    var dataToList2 = query2.ToList();
    List<object> deletedItems2 = dataToList2.Where(item => axOrderDeleted(item.AxaptaSalesId)).Cast<object>().ToList();
    var dataToGrid2 = dataToList2.Except(deletedItems2);
    //Query 2 end
    var combined = datatoGrid.Union(dataToGrid2);
    var lol = combined.Distinct();
    e.Result = lol;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:21:41+00:00Added an answer on May 27, 2026 at 10:21 pm

    I see that you are using the .Cast<>() extension method to cast the resulting items to object which indicates to me that you are having a problem reconciling the two anonymous types. Assuming that the results of query1 and query2 are anonymous types with the same property names and types, this should not be the case.

    Anonymous types provide overridden Equals() and GetHashCode() methods which are defined in terms of the Equals() and GetHashCode() implementations of the properties. Therefore the .Distinct() operator should work for two anonymous type objects of the same type without requiring the IEqualityComparer implementation.

    Try dropping the .Cast<object>() extension methods from your queries. The .Union() operation you are subsequently performing will only be allowable if the two queries are of the same data types. If that’s the case, your .Distinct() method should work just fine.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove duplicates from a MySQL table using ALTER IGNORE TABLE +
I'm trying to remove duplicate entries from a list which contains a generic object.
Possible Duplicate: Python: How to remove /n from a list element? I'm trying to
I am trying to remove duplicates in my listview. This function: procedure RemoveDuplicates(const LV:TbsSkinListView);
I'm trying to remove a color from a picture imported (JPG) in Flash CS4
I'm trying to remove all but the first child component from a Java Container.
I'm trying to remove a class attribute from an element and add the class
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
I'm trying to figure out a single sql statement to remove duplicate records from
I am trying to remove duplicate data from my database. I found a nice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.