EF中Linq语句多个查询条件的情况


http://blog.csdn.net/q107770540/article/details/5724013

 

public string GetStudata()
{
string name = Request.QueryString["name"];
string sex = Request.QueryString["sex"];
string qurstr = "";
var stus = from p in data.Student
select p;
if (!string.IsNullOrEmpty(name) && sex != "Choose..." && sex != null)
{
stus = stus.Where(q=>q.name.Contains(name)&&q.sex==sex);
}
if (string.IsNullOrEmpty(name) && sex != "Choose..." && sex != null)
{
stus = stus.Where(q => q.sex == sex);
}
if (!string.IsNullOrEmpty(name) && sex == "Choose..." && sex!=null)
{
stus = stus.Where(q => q.name.Contains(name));
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM