我有一个List<t>
和一个DataTable
。List<Product>
通过使用 Linq,我想检索DataTable
.
product
( List<Product>
)名单
Number TechnicalDescription
1 This is the A item
2 This is the B item
3 This is the Z item
桌子
Name Description
A This is the A item
B This is the B item
C This is the C item
D This is the D item
结果:List<Product>
Number TechnicalDescription
3 This is the Z item
这 是我需要的提琴手 SQL 示例,但使用的是 Linq。
我已经尝试过了,但不起作用。
List<Product> productList = THE_LIST;
DataTable dtProducts = THE_TABLE;
var myNewList = from e in productList
join p in dtProducts.AsEnumerable()
on e.TechnicalDescription.ToLower()
equals p.Field<string>("Description").ToLower()
into productGroup
from p in productGroup.DefaultIfEmpty(new { ID = "0", TechnicalDescription = "" })
where p != null
select new
{
ID = e.ID,
TechnicalDescription = e.TechnicalDescription
};