Question

var test = new List<String>();
test.Add("Wendys");
test.Add("Olive Garden");
test.Add("McDonalds");
test.Add("Fridays");

(from r in db.Restaurants where r.Restaurant_Name.StartsWith(restName) 
&& r.RestaurntName.Contains(List<String> test) 
select r.Restaurant_Name).Take(matchingCount).toList();    

How do I get the code correct so that it only returns from Restaurant DB a restaurant name that matches on of the items in the List<string>

Était-ce utile?

La solution

you should inverse the order of the expression

(from r in db.Restaurants where r.Restaurant_Name.StartsWith(restName) 
&& r.any(c=>test.contains(r.Restaurant_Name))
select r.Restaurant_Name).Take(matchingCount).toList();    

Autres conseils

Do you mean something like this?

db.Restaurants
  .Where(x => txt.Contains(x.Restaurant_Name))
  .Select(x => x.Restaurant_Name)
  .Take(matchingCount).ToList();

try this:

list<string> myOptions = db.Restaurants.Where(r=> 
        r.Restaurant_Name.StartsWith(restName) && 
        test.Contains(r.Restaurant_Name))
   .Select(r => r.Restaurant_Name).take(matchingCount).toList();

this should return a list of string object

I am not sure if what you want is just 1 option, if so try this:

string myOption = db.Restaurants.FirstorDefault(r=> 
        r.Restaurant_Name.StartsWith(restName) && 
        test.Contains(r.Restaurant_Name))
   .Select(r => r.Restaurant_Name);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top