我正在学习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