3

我有一个List<t>和一个DataTableList<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
                 };
4

1 回答 1

3

尝试这个:

var table = 
    dtProducts.AsEnumerable()
        .Select(r => p.Field<string>("Description")).ToList();
var result = 
    productList
       .Where(p => !table.Any(t => StringComparer.OrdinalIgnoreCase.Equals(t, p.TechnicalDescription)));
于 2013-10-23T00:14:20.007 回答