Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda expression with <bool> and System.Nullable<bool>

This can't compile:

void Foo()
{
    using (var db = new BarDataContext(ConnectionString))
    {
        // baz is type 'bool'
        // bazNullable is type 'System.Nullable<bool>'
        var list = db.Bars.Where(p => p.baz && p.bazNullable); // Compiler: 
            // Cannot apply operator '&&' to operands of type
            // 'System.Nullable<bool> and 'bool'
    }
}

Do I really have to make this through two runs, where I first use the as condition and then run through that list with the nullable conditions, or is there a better clean smooth best practice way to do this?

like image 903
radbyx Avatar asked Jun 27 '26 06:06

radbyx


1 Answers

p.bazNullable.GetValueOrDefault()
like image 113
gsharp Avatar answered Jun 28 '26 18:06

gsharp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!