简体   繁体   中英

Returns “Enumeration yielded no results” in LINQ statement

I have trouble with following linq query:

IEnumerable<PRINTER> alreadyexist = db.PRINTER.ToList().Where(c => c.REG_ID.Equals(1) && (c.NAME.Equals(“p3”) || c.IP.Equals(“4”)));

It does not return actual result. Instead, it just shows Enumeration yielded no results . Only after placing the OR operation, i got this message actually.

In general this message appear when there is no data satisify the constraints of the Where Statement, so double check your database table, to ensure that there will be data satisfy those constraints

any way we can improve the query, or write it in another way like the following

IEnumerable<PRINTER> alreadyexist = db.PRINTER.Where(c => c.REG_ID == 1 && (c.NAME == “p3” || c.IP == “4”));

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