在Linq to SQL中我有一個表達式返回一個int,並且我想根據返回一個布爾值的那個表達式創建一個表達式。 int可用於OrderBy(score)
,布爾值可用於Where(ifScore)
。我無法弄清楚如何使用分數來定義ifScore
,並希望得到一些幫助。在Int表達式中創建一個bool Linq to SQL表達式
Expression<Func<Model, int>> score = p =>
(testList.Count() > 0 && p.Name.Contains(testList.FirstOrDefault()) ? 1 : 0);
Expression<Func<Model, bool>> ifScore = p =>
//how to say if score > 2
你的第一個表達式只能返回1或0的整數,這基本上是一個真/假。不知道你在努力完成什麼 – Aducci