Ion
Ion

Reputation: 559

select objects from 1 list that are not in other list

i´m tryin to obtain data from one list that not in another list, the 2 list have the same data type, the two list are a list of Articles whith diferent data:

public class Articles
{
    public string ArticleName{ get; set; }
    public string ClientName { get; set; }
    public DateTime Date { get; set; }
    public string ProviderName { get; set; }
    public string Seller{ get; set; }
    public string ArticleCode { get; set; }
    public float Price { get; set; }
    public float Stock { get; set; }
    public int MiniumUnit { get; set; }
}

List<Articles> LstLowRotation=new List<Articles>();
List<Articles> LstVeryLowRotation=new List<Articles>();

and then i add data in each list(some are differents) and then:

 LstVeryLowRotation = LstVeryLowRotation.Where(x => !lstLowRotation.Any
 (z => z.ArticleCode == x.ArticleCode)).ToList();

but not give me the expected result, they give me more articles that is suposed.

Any idea why don´t works?

also i try

LstVeryLowRotation.except(Lst.LowRotation)

I know is that supossed to work, i have tested with only a few data and works fine, but when i add the data from a datareader it does wrong, and the strangest thing is that when i run appears data that is not in one list or the other list, it´s supposed to be impossible!!!

I edited the names to be more clear.

Upvotes: 0

Views: 105

Answers (2)

Ion
Ion

Reputation: 559

Finally all the people was right, the problema its in the database, the ArticleCode have many strange characters that had to make the comparison does not work.

THANKS TO ALL PEOPLE TO HELP

Upvotes: 0

tom.dietrich
tom.dietrich

Reputation: 8347

Try Enumerable.Except() - I think it will do exactly what you want if you add an equality override for the Articles class telling it to compare the Articulo property.

https://msdn.microsoft.com/en-us/library/vstudio/Bb300779(v=VS.100).aspx

Upvotes: 2

Related Questions