2016-07-27 145 views
1

目前我正在尋找像下面陣列在LINQ查詢搜索參數

resourcesDB.Where(x => x.Resource_Type == 1 && (x.Resource_Ext.ToLower() ==".doc" || (x.Resource_Ext.ToLower() == ".docx"))).ToList(); 

,但我想搜索使用數組作爲搜索參數的記錄,我的數組是

var docExts = new[] { ".pdf",".doc", ".docx", ".xls", ".xlsx" }; 

我要像

resourcesDB.Where(x => x.Resource_Type == 1 && (x.Resource_Ext.ToLower() == [from docExts ])).ToList(); 

是否有可能如何實現這一目標?

回答

2

包含在數組中你應該做的還指定x.Resource_Ext

var docExts = new[] { ".pdf",".doc", ".docx", ".xls", ".xlsx" }; 

var result = resourcesDB.Where(x => x.Resource_Type == 1 &&  
            docExts.Contains(x.Resource_Ext.ToLower()); 
2

嘗試

.Where(x => x.Resource_Type == 1 && docExts.Contains(x.Resource_ext.ToLower()))