This is my model;
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<LocalBusiness> Businesses { get; set; }
}
}
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..
var companyquery = from c in db.LocalBusiness
where c.Category = Category.Name
select c;
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!!
My controller, is this what you mean?
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);
}