i am new in ASP.NET its my first application in ASP.NET MVC how to get data of product and category in Product Object please check my controller.
Category Class
public partial class Category
{
public Category()
{
Products = new HashSet<Product>();
}
public int categoryId { get; set; }
[StringLength(50)]
public string categoryTitle { get; set; }
public int? categoryIndex { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
Product Class
public partial class Product
{
public int Id { get; set; }
public int categoryId { get; set; }
[StringLength(50)]
public string productTitle { get; set; }
[UIHint("tinymce_jquery_full"), AllowHtml ]
public string productDescription { get; set; }
[StringLength(1)]
public string status { get; set; }
public virtual Category Category { get; set; }
}
Controller
public ActionResult Index()
{
DataContext db = new DataContext();
// var products = db.Products.Where(a =>a.productImage != // here is some code for getting list of products with category details )
// want to save value in product so that i can read like this
// products.productTitle;
// products.productDescription ;
// products.Category.categoryId ;
// products.Category.categoryTitle ;
return View(products);
}
its easy to get all product data in "var product" variable but i need all producta with category id and category name like this products.Category.categoryTitle ;
i am using "code first from database" approach.