Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda expression to get data for a single column where values "In"

Tags:

c#

lambda

I have a SQL table "tablex" with 3 columns(A, B ,C ).

The following lambada expression returns 10 rows.

var versions = versionRepository.GetVersions(a.id)

Column B of the 10 results store data as: 1,2,3,4,5,6,7,8,9,10

Can someone help me with the lambda expression to only get results for column C where b in (2,3,4).

So I should only get 3 rows of column C data.

like image 311
user1204195 Avatar asked Nov 30 '25 05:11

user1204195


1 Answers

Use the Where extension method to filter the data, and the Select extension method to get only the C property:

var versions =
  versionRepository.GetVersions(a.id)
  .Where(v => v.B >= 2 && v.B <= 4)
  .Select(v => v.C);

(The part v => v.C is an example of a lambda expression.)

like image 68
Guffa Avatar answered Dec 02 '25 18:12

Guffa