Comapare Ienumerable <int>和List <Entity>并获得匹配的ID

use*_*567 0 c# comparison ienumerable list

Ienumerable<int> Temp1;来自DB

和其他List<entity> Temp2;具有属性Id和名称.

我想compare Temp1 & Temp2(Id)找到匹配的值并将其放在List中.

实现这个的最佳方法是什么?

谢谢

Kam*_*ski 6

使用SelectIntersect

var sameIds = Temp2.Select(x=>x.Id).Intersect(Temp1);
Run Code Online (Sandbox Code Playgroud)

首先只选择Id为新,IEnumerable<int>然后IEnumerable<int>将其与当前可用的相交,将为您提供匹配的ID