2011-05-24 33 views
0

確實是一個快速問題。
我正在努力實現Linq2Entities語句,該語句可能會針對特定的「字段」使用多個值。我通過了一些字符串到getClientsProjected()我可以很容易地比較單個值。但是我的頁面上有多個下拉菜單,除此之外,我用昏迷將字符串分隔開來,然後用它將其拆分爲string[]__ACCOUNT_SITE = "1234,5678"(見下面的代碼),我試過了/的foreach /不含有哪工作?「ArrayIndex」LINQ表達式節點類型不受LINQ to Entities支持 - 使用接口&ReportViewer

public IQueryable<ClientViewModel> getClientsProjected(string __ACCOUNT_SITE, string __ACCOUNT) 
{ 
    var projectedClients = from c in getClosedSRs() 
          select new ClientViewModel 
          { 
           _ACCOUNT_ID_CSR = c.ACCOUNT_ID_CSR, 
           _ACCOUNT = c.ACCOUNT, 
           _ACCOUNT_FAMILY = c.ACCOUNT_FAMILY, 
           ... 
           ... 
           _ACCOUNT_SITE = c.ACCOUNT_SITE 
          }; 

    if (String.IsNullOrEmpty(__ACCOUNT) != true && __ACCOUNT != "ALL") 
    { 
     //this works fine as an __ACCOUNT is of a single value 
     projectedClients = projectedClients.Where(c => c._ACCOUNT == __ACCOUNT); 
    } 

    if (String.IsNullOrEmpty(__ACCOUNT_SITE) != true && __ACCOUNT_SITE != "ALL") 
    { 
     String[] splitSites = __ACCOUNT_SITE.Split(','); 
     //???????????????????????????????????????????????? 
    } 
    return projectedClients; 
} 

現在,你們中的大多數,這將使得完整意義上的。我讀過很多文章,但沒有找到正確的答案。但是我不能使用Linq2SQL,因爲已經使用L2E,接口和ReportViewer構建了我的整個站點。

任何解決方法?

回答

0

如果您想篩選基於在splitSites值projectedClients,然後使用:

if (String.IsNullOrEmpty(__ACCOUNT_SITE) != true && __ACCOUNT_SITE != "ALL") 
{ 
    String[] splitSites = __ACCOUNT_SITE.Split(','); 
    projectedClients = projectedClients.Where(x => splitSites.Contains(x._ACCOUNT); 
} 
+0

我曾嘗試這一點,得到了以下錯誤:LINQ到實體無法識別方法「布爾包含[字符串](System.Collections.Generic.IEnumerable'1 [System.String],System.String)'方法,並且此方法不能轉換爲存儲表達式。 – Jake 2011-05-24 11:46:53

+0

您需要先創建清單。嘗試使用:'List splitSites = __ACCOUNT_SITE.Split(',')。ToList();'代替數組。 – Leons 2011-05-24 11:57:25

+0

我加了ToList();以上轉換爲列表。 – Leons 2011-05-24 11:59:20

相關問題