Limna
Limna

Reputation: 403

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.

Upvotes: 1

Views: 997

Answers (1)

Hakan Fıstık
Hakan Fıstık

Reputation: 19511

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”));

Upvotes: 1

Related Questions