简体   繁体   English

我如何在 linq 中使用 2 个条件

[英]how i can use 2 condition in where linq

my code not answer我的代码没有回答

var SabteGheybat = from row in db.InfoStudents.Where(p => p.PayeTahsili == comboBox1.SelectedItem.ToString()
                && p.Gheybat != Mydate)

                               select row;

If there is an error please provide error information to everyone.如果有错误请提供错误信息给大家。
If your query has no error message then it looks like you forget lazy query.如果您的查询没有错误消息,那么您似乎忘记了lazy查询。
please use ToList() because your query is legal.请使用ToList()因为您的查询是合法的。

var SabteGheybat = (from row in db.InfoStudents.Where(p => p.PayeTahsili == comboBox1.SelectedItem.ToString()
                && p.Gheybat != Mydate)
    select row).ToList();

i try the same logic and it's result:我尝试相同的逻辑,结果如下: 在此处输入图片说明

and you can simplify query like:您可以简化查询,如:

var SabteGheybat = db.InfoStudents.Where(p => p.PayeTahsili == comboBox1.SelectedItem.ToString()
                && p.Gheybat != Mydate)

if you are getting error you need change your code like this:如果出现错误,则需要像这样更改代码:

var con = comboBox1.SelectedItem.ToString()
var SabteGheybat = from row in db.InfoStudents.Where(p => p.PayeTahsili == con
        && p.Gheybat != Mydate)

OR use this format:或使用此格式:

var con = comboBox1.SelectedItem.ToString()
var SabteGheybat =  db.InfoStudents.Where(p => p.PayeTahsili == con
        && p.Gheybat != Mydate).toList()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM