Retreive ContentPart using IContentManager filtered by case insensitive field

Topics: Writing modules
May 28, 2015 at 6:00 PM
Edited May 28, 2015 at 6:01 PM
In the development of an Orchard module, how do I retrieve ContentParts case insensitively filtered by a field?
I have tried:
var name = viewModel.Name.ToUpper();
var samples = _contentManager.Query<SamplePart, SamplePartRecord>()
                .Where(x => x.Name.ToUpper() == name)
                .List();
and I'm getting error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

But when I tried to retrieve without bothering if it's case sensitive
var name = viewModel.Name;
var samples = _contentManager.Query<SamplePart, SamplePartRecord>()
                .Where(x => x.Name == name)
                .List();
No errors reported.

What gives?
May 28, 2015 at 11:48 PM
Edited May 28, 2015 at 11:48 PM