开发者

Linq - Except one list with items in another

I think my question is easy, but I'm a newbie in linq... So I'm having a hard time here

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

These ItemsTOP aren't in my system, but the user can choose which itemTOP to import to the system.

The imported ItemsTOP becomes an object Item { Id, IdTOP, Name }

So, when the s开发者_如何学Cystem calls serviceTOP, before showing them to the user, I must filter the already imported items from the list.

Let's go to 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 kind of works, but it returns a list of strings containing only the id.

I'd like to select both id and name of the TOP.


Change this:

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

To this:

listTOP.Select(i => new { ID = i.id, Name = i.Name} )
       .Except( i => i.IdTOP );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜