3
我有一個List<t>
和DataTable
。通過使用Linq,我想檢索DataTable
中不存在的產品List<Product>
的列表。左加入列表<t>與Datatable -Linq
的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
Here是我所需要的提琴手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
};
的最佳解決方案,只有一個建議'等於(T,p.TechnicalDescription)' – Coyolero
@Coyolero,好,謝謝。 –