c# - How to query first and last name in Entity Framework? -


i want have intelligent search box finding objects person's name. in linq, this:

users = users.where(m => m.firstname.contains(query) || m.lastname.contains(query) || (m.firstname + " " + m.lastname).contains(query) || (m.lastname + " " + m.firstname).contains(query) || (m.lastname + ", " + m.firstname).contains(query)); 

but seems might bad way things, , i'm not sure how performance degrades linq. type of statement fine or there way improve on this?

ef going convert linq query sql , execute sql statement against database. query above translate clause or. each contains() translate like in sql. so, you'll like:

select * users firstname '%query%' or lastname '%query%' 

as long resulting query performs okay, should fine.

if doesn't perform well, @ adding index or maybe using full-text search.

https://msdn.microsoft.com/en-us/library/ms142571.aspx


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -