我有两个数据源,想要遍历第一个,过滤另一个数据源中存在的字段,如下面的伪代码所示:
DataContext1 db1 = new DataContext1();
DataContext2 db2 = new DataContext2();
foreach(Address address in db1.Addresses.Where(l => l.LocationCode in db2.AddressList.Select(c => c.LocationCode)))
{
// perform operations
}
完成此操作的正确语法是什么?
答案 0 :(得分:0)
在db2中选择后添加AsEnumerable()
foreach(Address address in db1.Addresses.Where(l =>
db2.AddressList.Select(c => c.LocationCode).AsEnumerable().Contains(l.LocationCode)))
{
// perform operations
}