开发者

Syntax for LINQ to DataSets Row Filter in C#?

开发者 https://www.devze.com 2023-01-08 08:47 出处:网络
I have two DataTables one is Primary Table and the rest is a sub table (I am using strongly typed dataset).

I have two DataTables one is Primary Table and the rest is a sub table (I am using strongly typed dataset).

Example

Employee Table

Id   Name   City 开发者_运维问答
1    AAA    NY 
2    BBB    BB
3    CCC    AA

CityInitials Table

CityInitial
NY    
FF  
CC
RR 
RNF
YOT
DDD  

I have to select rows from employee table only when the 'city' in Employee table matches any of the CityInitials of CityInitials Table. i tried

var _filter = EmployeeTable.AsEnumerable().
Select(x=>x.Field<string>("City")).Contains
(CityInitials.AsEnumerable().Field<string>("CityInitials").Select(row=>row);

Please suggest what is the proper query to achieve the result?


I assume these are in fact typed datasets? Without knowing exactly what you're working with, I'd call the following an approximation of what I'd expect to work:

var cities = CityInitials.Rows.Select(x => x.CityInitials).ToList();
var _filter = EmployeeTable.Rows.Where(x => cities.Contains(x.City));
0

精彩评论

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

关注公众号