1

I have implemented as search function on my website that uses 1 table using the following function.

Search function

[HttpPost]
        public ActionResult Results(string SearchString)
        {
            using (var objCtx = new ApplicationDbContext())
            {
                var Restaurant = from u in objCtx.Restaurants
                           select u;


                if (!String.IsNullOrEmpty(SearchString))
                {
                    Restaurant = Restaurant.Where(s => s.Name.Contains(SearchString));
                }

                return View(Restaurant.ToList());
            }
        }

Is it possible to extend this function so that it can search through multiple tables without using a search engine such as Lucene.net?

Any help would be greatful.

1 Answer 1

3

You can query the tables then merge the iqueryable lists

var Restaurant = from u in objCtx.Restaurants
                       select u;

if (!String.IsNullOrEmpty(SearchString))
{
    Restaurant = Restaurant.Where(s => s.Name.Contains(SearchString));
}

// Second table.
var Restaurant2 = from u in objCtx.Restaurants2
                       select u;


if (!String.IsNullOrEmpty(SearchString))
{
    Restaurant2 = Restaurant2.Where(s => s.Name.Contains(SearchString));
}

return View(Restaurant.Union(Restaurant2).ToList());

or

return View(Restaurant.Concat(Restaurant2).ToList());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.