avg_bloke
avg_bloke

Reputation: 214

Linq to filter result from database

I have an existing function that returns a model data

var GetTableData = await _camService.GetTableData();

This returns a list Task<List<GetTableDataModel>> of model properties.

Now, I want to filter the result based on one of the model property (eg. email)

like, GetTableData where email='[email protected]'

Upvotes: 0

Views: 322

Answers (2)

Martin Zikmund
Martin Zikmund

Reputation: 39102

You can use LINQ to perform filtering:

var filteredData = data.Where( item => item.email == "[email protected]" ).ToArray();

In this case however I don't see the reason to retrieve all data at once when they are just filtered subsequently. I think it would be more efficient to filter them on the database side, within your service.

Upvotes: 1

XardasLord
XardasLord

Reputation: 1947

var filteredData = GetTableData.Where(x => x.email == "[email protected]");

I would suggest you to create a function in which you will filter the data on the database side instead of querying all the data.

Upvotes: 3

Related Questions