-1

i'm new to linq and mvc so far this is to get name base on name search

return repository.GetAll().Where(
    m => m.Name.ToLower().Contains(name.ToLower()));

however, i want to be able to get information from another table that associated with name like address, city, etc.. base on the name search. so at the end if i type in Pete, it will returns.

pete a, 111 test ave, holland, usa;
pete c, 222 test rd, holland, usa;

can someone help please. thanks

user3731575
  • 121
  • 11
  • Have a look to the following question: http://stackoverflow.com/questions/2767709/c-sharp-joins-where-with-linq-and-lambda – Juan Mar 13 '15 at 16:39
  • What does your database schema look like? – gunr2171 Mar 13 '15 at 16:39
  • really just 3 tables one has id, name, one has id address, and one has nameid, addressid. so when you search for a name, i want to be able to pull all addresses that that person has been to or if you search for address i want to pull all people that were at the search address. – user3731575 Mar 13 '15 at 19:07
  • any help is really aprreciated – user3731575 Mar 13 '15 at 21:56
  • Whether or not you need `ToLower` depends on the database collation, You may not need it at all. But what exactly is your problem in combining the data into one result? – Gert Arnold Mar 15 '15 at 19:40

1 Answers1

1

Try something like..

var joinedQuery = from n in names
                  join a in address on n.name equals a.name
                  select new { aName = n.name, anAddress = a.address };

names is your names repository and address is the addressed repository

krilovich
  • 3,475
  • 1
  • 23
  • 33