我正在學習LINQ to sql的過程。如果LINQ中有其他條件
是否有可能在LINQ to SQL中寫入以下條件?
條件1
var query1 =
if
from q in db.Students
q.fees =="paid" && q.activites == "good" && count == 0
select q
save "OK" to the property result.
else
from q in db.Students
q.fees =="paid" && q.activites == "good" && count == 2
select q
save "better" to the property result.
else
from q in db.Students
q.fees =="paid" && q.activites == "good" && count > 2
select q
save "bad" to the property result.
private string _result;
public string Result
{
get { return this._result; ; }
set { this._result; = value; }
}
麻煩引導。
更新編輯:
var query1 =
(from q in db.Students
q.fees =="paid" && q.activites == "good"
select q).Any();
if(count ==0 && query1 == true)
{
this.Result = "OK"
}
esle if(count == 2 && query1 == true)
{
this.Result = "better"
}
esle
{
this.Result = "bad"
}
這將是一個辦法?
http://stackoverflow.com/questions/15909926/linq-if-else-condition/15909991#_=_看到 –
因爲這是代碼的一面,爲什麼不使用常規的如 - else模式並將必要的linq查詢放入這些塊中? – valverij
可以請你舉一個例子 – user1221765