Reputation: 251
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?
Upvotes: 4
Views: 8341
Reputation: 937
var Lang= from language in dc.Languages
where language.LangName.StartsWith("Eng")
select language.LangName;
Upvotes: 0
Reputation: 4114
Use StartsWith instead of Contains
var query = dc.Languages.Where(p=>p.LangName.StartsWith(txtBxLangNameFilter.Text));
Upvotes: 0
Reputation: 263833
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));
Upvotes: 13