2013-10-08 38 views
1

我有以下查詢。其中,我正在進行一次Take(2100),以避免2100次打擊限制。LINQ Select和Lambda避免2100 rpc限制

var query = 
    from result in staging_sparc_sophis_trade.AsQueryable() 
    where deals.Take(2100).Contains(result.TRADE_ID) 
    select new traded_product() 
    {     
     Deal = result.TRADE_ID, 
     CostCentre = result.FTP_COSTCTR, 
     InvolvedPartyId = R_GEN_002(result.hsbc_source_system_instance, "", result.CNPTY_ACRONYM 
    }; 

我想知道的是,有沒有辦法可以去除服(2100)的一部分,並在交易訂單拉姆達語句來替換它來檢查,如果這筆交易是在列表(交易)我正在尋找?

+0

的可能重複的[使用時擊中2100參數限制(SQL服務器)包含()](http://stackoverflow.com/questions/656167/hitting-the-2100-parameter-limit-sql -server-when-using-contains) –

+0

@MikaelÖstberg是的,我正在考慮做一個循環,並在最後加入所有結果。但我不確定是否有優雅的Lambda解決方案。不要想。 – vwdewaal

+0

我們使用了一個用於mssql的參數化數據表。這可能不是完美的解決方案,但應該解決問題。 – Mixxiphoid

回答

1

我發現有兩種方法可以解決問題。 解決方案1.如果我直接在SqlServer物理機器上運行查詢,則不會發生此問題。

執行濾波,下一部分: 刪除「Where子句」

var query = 
from result in staging_sparc_sophis_trade.AsQueryable() 
--where deals.Take(2100).Contains(result.TRADE_ID) 
select new traded_product() 
{     
    Deal = result.TRADE_ID, 
    CostCentre = result.FTP_COSTCTR, 
    InvolvedPartyId = R_GEN_002(result.hsbc_source_system_instance, "", result.CNPTY_ACRONYM 
}; 

添加過濾部分在這部分代碼。它運行得慢一點,但仍然有竅門。我認爲它運行速度較慢,因爲我在每一次迭代中搜索完整列表。

foreach (var result in query) 
{ 
if (!deals.contains(result.TRADE_ID)) 
{ 
--Actions 
} 
}