When debugging with VS studio , i have faced an error that return
How should I fix this
I use ef code first on this project
Here is the controller , DbContext and the Models
public class ApplicationController : Controller
{
ApplicationDbContext _context = new ApplicationDbContext();
public ActionResult Index()
{
List<Brand> brands;
brands = _context.Brands.ToList();
return View(brands);
}
}
DbContext
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext()
: base("name=ApplicationDbContext")
{
}
public virtual DbSet<Brand> Brands { get; set; }
public virtual DbSet<Product> Products { get; set; }
}
Brand
public class Brand
{
[Key]
public int brand_id { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
public string brandname { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
public string program { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
public string currency { get; set; }
public string note { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime timestart { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MM-yyyy}")]
public DateTime timeend { get; set; }
public virtual List<Product> Products { get; set; } = new List<Product>();
}
Product
public class Product
{
[Key]
public int product_id { get; set; }
[ForeignKey("Brand")]
public int brand_id { get; set; }
public virtual Brand Brand { get; private set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
public string productname { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
public string condition { get; set; }
[Required(ErrorMessage = "Nhập thiếu kìa fen.")]
[Column(TypeName = "numeric")]
public decimal rebate { get; set; }
public string note { get; set; }
}
I appreciate every help