Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching Single Record using two conditions in LINQ

I have a table which I am updating a single record using LINQ, but my condition to fetch that record is 2. My condition is this:

   Test p = dt.Tests.Single(c => c.ID == getID);

But I want to add another condition:

Where Cust_ID == 1. Something like this:

  Test p = dt.Tests.Single(c => c.ID == getID && t=> t.Cust_ID == 1);

But I cannot get hold of this situation using LINQ. Any help pls?

like image 365
RG-3 Avatar asked Jan 27 '26 22:01

RG-3


1 Answers

You need to put the logical operator inside the lambda:

dt.Tests.Single(c => (c.ID == getID && c.Cust_ID == 1) )

The inner parentheses are not needed; I added them to clarify that it's all one lambda.

like image 167
SLaks Avatar answered Jan 29 '26 11:01

SLaks