有沒有機會在linq查詢中運行c#方法? 我需要做這樣的事情:在linq查詢中調用c#方法(實體框架)
//...
class Match {
public double PrecentageMatching(string s1, string s2) {
//...
return result; // value from 0.0 to 1.0
}
}
//...
string pattern = "nameOfRecord";
var similarRecords = db.Table.Select(
r => Match.PrecentageMatching(r.name, pattern) > 0.5
);
我知道有LINQ不會知道的方法PrecentageMatching。但我想知道是否有辦法做到這一點?
我正在使用實體框架。 我需要在數據庫端沒有存儲過程和彙編。我沒有訪問數據庫。
它的。加工。謝謝。還有一件事...有沒有更改這個查詢的選項,我可以接收所有字段?因爲在你的查詢中,我只收到名稱字段。 – nosbor
當然。刪除'.Select(r => r.name)'行並將最後一行改爲'.Select(x => Match.PrecentageMatching(x.name,pattern)> 0.5);'。 –