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?
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.
In the lambda expression you should use the same alias
Test p = dt.Tests.Single(c => c.ID == getID && c.Cust_ID == 1);
You're trying to use two separate lambda expressions for a single argument. I suspect you're looking for:
Test p = dt.Tests.Single(c => c.ID == getID && c.Cust_ID == 1);
If that's not the case, please give us more details about what you're trying to test in your conditions.
Test p = dt.Tests.Single(c => c.ID == getID && с.Cust_ID == 1);
You're almost there, you just have the syntax wrong:
dt.Tests.Single(c => c.ID == getId && c.Cust_ID == 1);
You simply use the same symbol and combine the conditions.
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.