我正在使用將linq表達式轉換爲事件查詢的庫。 (的StreamInsight)。將表達式<Func>選擇器綁定到linq查詢
我需要解決這個問題:
鑑於一些值,並結合值的表達式。
var a = new[] { "a", "b", "c" };
var b = new[] { "x", "y", "z" };
Expression<Func<string, string, string>> combine = (x, y) => x + ":" + y;
我需要將組合函數綁定到以下查詢,同時仍保持表達式語法。
var query =
from f in a
from g in b
select combine(f, g);
query.Dump();
不幸的是,這個LINQ語句中的目標應用程序不支持Func<string, string, string>
在它的原始格式,因爲該查詢在運行時解釋。
我得到這個錯誤:附加信息:下面的表達不會被微軟複雜事件處理LINQ提供程序支持:「調用(值(System.Func`3 ...
我想我會解決如果我可以重現表達,因爲它本來的問題:
var query =
from f in a
from g in b
select x + ":" + y;
我想查詢的選擇部分傳遞到一個函數作爲Expression<Func<...
參數
我想這一點,這顯然完全不是那麼回事:
var query =
a.SelectMany(a1 => b, (x, y) => new { x, y })
.Select(_ => combine(_.x, _.y));
我簡化了這個問題,但作爲參考,真正的查詢看起來是這樣的:
var ms =
requestStream
.AlterEventLifetime(
_ => _.StartTime - TimeSpan.FromMilliseconds(10000),
_ => _.EndTime + TimeSpan.FromMilliseconds(10000) - _.StartTime)
.SelectMany(requestData => responseStream
.AlterEventLifetime(
_ => _.StartTime - TimeSpan.FromMilliseconds(10000),
_ => _.EndTime + TimeSpan.FromMilliseconds(10000) - _.StartTime),
(requestData, responseData) => new {requestData, responseData})
.Where(@t => @t.requestData.CorrelationTicketId == @t.responseData.CorrelationTicketId)
.Where(@t => @t.requestData.CorrelationTicketId > 0
&& @t.requestData.SuccessFailureCode != 3001)
.Select(@t => expression(@t.requestData, @t.responseData));
'.SelectMany(a1 => b,combine)'工作嗎? – Rawling
否,CS1929 '字符串[]' 不包含關於 '的SelectMany' 和最好的擴展方法過載「Queryable.SelectMany <字符串,字符串,字符串>(IQueryable的,表達> >,表達>)」需要類型的接收器‘的IQueryable ’ –
Jim
除此之外,我真的需要弄清楚如何將其綁定到的選擇,因爲我真實的場景有很多,其中條款也是如此。 – Jim