How to test a lamda expression var query result is null?

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2011-03-13T08:03:25Z Indexed on 2011/03/13 8:09 UTC
Read the original article Hit count: 371

Filed under:
|
|
|
|
        var query = from emp in dbEmp.Employees
                    join dept in dbEmp.Departments
                        on emp.DeptID equals dept.DeptID
                    where dept.DepartmentName.Contains(this.TextBox1.Text)
                    select new
                    {
                        EmpID = emp.EmpID,
                        EmpName = emp.EmpName,
                        Age = emp.Age,
                        Address = emp.Address,
                        DeptName = dept.DepartmentName
                    };

        if (query==null)
            Label1.Text = "no results match your search";

        GridView1.DataSource = query;
        GridView1.DataBind();

Everything works in the right way, but the label doesn't show the message when query result returns null. The label can show without condition(querry==null). So how to test if a var query result returns nothing? Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ