Link to home
Start Free TrialLog in
Avatar of kmitch62
kmitch62Flag for United States of America

asked on

Use Linq to entities to filter on alpha and numeric values

I have the following code in my method

            MyListViewModel viewModel = new MyListViewModel {
                MyList= repository.MyList
                .Where(m=> alphaFilter == (string)null || m.Title.StartsWith(alphaFilter))

this filters the list based on the first character in the string.  It works perfectly if the value passed as alphaFilter matches the first character of a the m.title.

My problem is that i want an alpha character to filter on the same character, but i want to be able to pass a "#" character and retrieve all entries that start with a numeric value.

in other words, i want my select list of alphaFilter characters to look like this...

# A B C D
not
1 2 3 4 5 6 7 8 9 0 A B C D

I know there is probably an easy solution, but i'm having trouble finding it.  Any help would be much appreciated
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kmitch62

ASKER

it was being populated by  .Select(x=>x.Title.Substring(0,1)  so there would only be one character. '#' is being added to the list at list[0].  that is the correct behavior.

as for the answer... that's exactly what i needed and I don't believe that i didn't see it myself.  Like i said, a simple answer that i was just missing.  Thanks for the help.