Tuesday 15 February 2011

c# - ToUpper() in lambda not working -



c# - ToUpper() in lambda not working -

var result = addresscontext.address_lookup .where(c => c.address_full.toupper().contains(term.toupper()) || c.address_full.toupper().contains(termmodified.toupper())) .select(e => new { id = e.address_id, label = e.address_full, value = e.address_full }) .tolist();

to ensure search non-case sensitive using toupper(). searching jimmy (with capital j). jimmy (all lower case) doesnt catch? why?

since you're using entity-framework, linq-to-sql framework, you're trying create database perform .toupper rather performing 1 in-memory if running through ienumerable. if query translation in framework doesn't back upwards function, either won't used or throw exception.

you can predict such behaviour checking whether you're calling function against iqueryable object, queues calls look tree translation, or ienumerable, uses foreach , yield returns handle evaluation. since linq functions extension methods, polymorphism doesn't apply here.

if you're not worried performance nail of getting every entry table in-memory, add together .asenumerable() call, , functionwill evaluate on localized data.

var result = addresscontext.address_lookup .asenumerable() .where(c => c.address_full.toupper().contains(term.toupper()) || c.address_full.toupper().contains(termmodified.toupper())) .select(e => new { id = e.address_id, label = e.address_full, value = e.address_full }) .tolist();

c# entity-framework lambda

No comments:

Post a Comment