title: Entity Framework Code First Linq MVC 3 Razor
body: <p>This is my model;</p>
  
  <pre><code>namespace AtAClick.Models
  {
      public class LocalBusiness
      {
          public int ID { get; set; }
  
          public string Name { get; set; }
          public int CategoryID { get; set; }
          public string address { get; set; }
          public string desc { get; set; }
          public int phone { get; set; }
          public int mobile { get; set; }
          public string URL { get; set; }
          public string email { get; set; }
          public string facebook { get; set; }
          public string twitter { get; set; }
  
          public string ImageUrl { get; set; }
  
          public virtual Category Category { get; set; }
  
      }
  
      public class Category
      {
          public int CategoryID { get; set; }
          public string Name { get; set; }
  
          public virtual ICollection&lt;LocalBusiness&gt; Businesses { get; set; }
      }
  
  }
  </code></pre>
  
  <p>I have a view which lists the categories and one which lists the businesses. I want another which list all the business in a certain category My question is, what would my Linq query in my controller look like? Something like..</p>
  
  <pre><code>var companyquery = from c in db.LocalBusiness
                     where c.Category = Category.Name
                     select c;
  </code></pre>
  
  <p>But obvioulsy this isn't working. I'm new to all this so thanks in advance for the help, and if you need anymore detail just ask. Thanks!!</p>
  
  <p>My controller, is this what you mean?</p>
  
  <pre><code> public ViewResult Browse(int id)
   {
  
              int categoryID = id;
  
              var companyquery = from c in db.LocalBusinesses
                                 where c.Category.CategoryID == categoryID
                                 select c;
  
              return View(companyquery);
   }
  </code></pre>