how to rotate around each record in linq and show that in view

Posted by Sadegh on Stack Overflow See other posts from Stack Overflow or by Sadegh
Published on 2010-05-25T09:32:32Z Indexed on 2010/05/26 10:31 UTC
Read the original article Hit count: 267

Hi, I have four tables in my database and i want to join that's and return record's and show that into searchController!

My query is this:

public IQueryable PerformSearch(string query)
{
    if (!string.IsNullOrEmpty(query))
    {
        var results = from tbl1 in context.Table1
                      join tbl2 in context.Table2 on tbl1.Id equals tbl2.Id
                      join tbl3 in context.Table3 on tbl2.Id equals tbl3.Id
                      join tbl4 in context.Table4 on tbl3.Id equals tbl4.Id
                      where tbl1.col2.Contains(query)
                      orderby tbl1.Count descending
                      select new
                      {
                          col1 = tbl1.Col1,
                          col1 = tbl1.Col1,
                          col1 = tbl1.Col1,
                                  .
                                  .
                                  .
                      };
        return results.AsQueryable();
    }
    else return null;
}

And this method called in SearchController as below:

public class SearchController : System.Web.Mvc.Controller
{
    public System.Web.Mvc.ActionResult Search(System.String query)
    {
        var search = new Search();
        ViewData["result"] = search.PerformSearch(query);
        return View("Search");
    }
}

I don't know how i can rotate around each record (plus vs intellisense feature) returned by PeformSeach method and show that in view! Also is this a good way?

thanks in advance

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about asp.net-mvc-2