Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter specific record using Contains in Entity Framework

I am working on an application where I need to filter a specific value but the reason I have only one parameter to filter it out.

string[] makes = { "UnitMakes:0:Enabled", "UnitMakes:0:UnitMake", "UnitMakes:0:Identity" };
var tt = makes.Where(x => x.Contains("UnitMake")).ToList();

Here tt returns a count of three but I need only the record "UnitMakes:0:UnitMake". I can’t add a where clause on a specific record that is because 0 is an index value that starts from 0 to any number. For example

UnitMakes:0:UnitMake
UnitMakes:0:Enabled
UnitMakes:0:Identity
UnitMakes:1:UnitMake
UnitMakes:1:Enabled
UnitMakes:1:Identity
UnitMakes:2:UnitMake
UnitMakes:2:Enabled
UnitMakes:2:Identity

I just want to return the UnitMake values not others.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Based on provided information you can do either:

.Where(x => x.EndsWith("UnitMake"))

or

.Where(x => x.Contains(":UnitMake"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading