Linq - except for one list with items in another

I think my question is simple, but I'm new to linq ... So it's hard for me here

My system calls a service called serviceTOP, which returns me a list of itemTOP {Id, Name} .

These ItemsTOP are not included in my system, but the user can choose which itemTOP to import into the system.

Imported ItemsTOPs become Item { Id, IdTOP, Name } objects

So, when the system calls serviceTOP, before showing them to the user, I must filter out already imported items from the list.

Go to the code:

 IList<ItemsTOP> listTOP = new ServiceTOP().GetItemsTOP(); IList<Items> list = new WCFServiceClient().GetItems(); var filteredListTOP = listTOP.Select( i => i.Id ).Except( i => i.IdTOP ); 

This type of work, but it returns a list of strings containing only the identifier.

I would like to select both id and TOP name.

Thanks in advance.

+6
source share
1 answer

Change this:

 var filteredListTOP = listTOP.Select(i => i.Id ).Except( i => i.IdTOP ); 

For this:

 var filteredListTOP = listTOP.Select(i => new { ID = i.id, Name = i.Name} ).Except( i => i.IdTOP ); 
+8
source

Source: https://habr.com/ru/post/885668/


All Articles