简体   繁体   中英

Return data based on condition in Linq C#

I have below query but it throws error

An exception was thrown while attempting to evaluate a LINQ query parameter expression

int? status = null;
BankDBContext.AccountDBs.Where(x => x.IsActive == (!status.HasValue? x.IsActive : (status.Value == 1))).ToList();

I want to return all records if status is null and if status has 1 return active records else in active records.

Thanks.

Return everything if null, active items if 1, else inactive

BankDBContext.AccountDBs.Where(x => status == null || x.IsActive == (status == 1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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