[英]Linq to Entities Where clause compare value that can be int or string
我有一個下拉列表,將提供數字或單詞ANY。 我需要創建一個包含WHERE子句的LINQ SELECT,該子句可以模仿以下SQL:
var p varchar2(3);
select ... from ...
where (
( (:p = 'ANY') and id in (select distinct id from Ids) )
or
(:p='1' and id = 42)
)
ps:我將使用表達式樹來處理OR方面:-)
這樣的事嗎?
string input = /***/
var result = Context.Entities
.Where(ent => (input == "ANY"
&& Context.UserIds.Select(usr => isr.Id)
.Distinct()
.Contains(ent.Id))
|| (input == "1" && ent.Id == 42))
.Select(ent => /***/);
免責聲明:從內存寫入,可能包含編譯時錯誤(打字錯誤等)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.