Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq to sql, begin with query

Tags:

c#

.net

sql

linq

I've a Languages table:

LangId LangName
1       English
2       EngTest
3       Germany

I want to write a query that shows LangName begins 'Eng'

var query = dc.Languages.Where(p=>p.LangName.Contains(txtBxLangNameFilter.Text));

I'm newbie in linq to sql. Can somebody show me how to write?

like image 491
baros Avatar asked Dec 12 '22 16:12

baros


1 Answers

Contains test if a string is found in a string at any location. Since you want to test for a string that starts with a certain string, use StartsWith().

var query = dc.Languages
              .Where(p => p.LangName.StartsWith(txtBxLangNameFilter.Text));
  • String.StartsWith Method
like image 106
John Woo Avatar answered Dec 14 '22 05:12

John Woo