Pages - Menu

2016年10月14日 星期五

LinqToExcel的VisitSubQueryExpression錯誤

要使用linq的in語法,
像是sql的
select * from AA where col in (select ….)
可以使用
var ids = {1, 2, 3};

var query = from item in context.items
            where ids.Contains( item.id )
            select item;
來做查詢。
但是一使用LinqToExcel 這樣用舊直接掛了,出現
VisitSubQueryExpression method is not implemented
後來查了google發現是linqToExcel 不支援子查詢的方式..
只好先將值塞去其他地方再用上面的方法取值。
var goal = new[] { "A","B","C" };
var excelContent = excelFile.Worksheet<customer>("Sheet1");
//會出現VisitSubQueryExpression 錯誤
var filter = excelContent.Where(p => goal.Contains(p.Customer));   
List<customer> tempExcel = excelContent.ToList<customer>();               
var result = tempExcel.Where(p => goal.Contains(p.Customer));
foreach (var item in result)
{
    string x = item.Customer;
}

沒有留言:

張貼留言