I had a very similar problem, but in my case, I found that I need to match the table name of the table to the table of tables , not the type name
- Type Name: NonTradingDay
- Database table name: dbo.NonTradingDays (has been pluralized )
Create Method:
[HttpPost] public ActionResult Create(NonTradingDay NonTradingDays) { if (ModelState.IsValid) { db.NonTradingDay.Add(NonTradingDays); db.SaveChanges(); return RedirectToAction("Index"); } return View(NonTradingDays); }
I tried "NonTradingDay", but still got zero; Then I looked at the name of the database table, tried "NonTradingDays", and a match was made (the argument is no longer zero).
I thought because I had a database context like:
public DbSet<NonTradingDay> NonTradingDay { get; set; }
Instead
public DbSet<NonTradingDay> NonTradingDays { get; set; }
source share