Linq on datatable and list< objects>给出错误的结果 [英] Linq on datatable and list<objects> giving wrong result

查看:72
本文介绍了Linq on datatable and list< objects>给出错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据表,我需要枚举它并检查List对象并从数据表中获取匹配的行。但由于某些原因,以下返回所有数据行,即使它不匹配。



我尝试过的事情:



I have datatable , I need to enumerate it and check against the List objects and take the matching rows from the datatable. But for some reason below returning all the datarows even though it's not matching.

What I have tried:

var joinForUpdate = 
    from rowA in ds.Tables[0].AsEnumerable()
    where fin.Select(y => rowA.Field<int>("B") == y.BID&& y.AID== rowA.Field<int>("A")).Any()
    select rowA;

推荐答案

您可能想要使用 Enumerable.Intersect(TSource) [ ^ ]获取两个列表中常用项目的方法。



You probably want to use Enumerable.Intersect(TSource)[^] method to get common items on both lists.

var commonitems = SomeList.Intersect(TheOtherList);


这篇关于Linq on datatable and list&lt; objects&gt;给出错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆