I have three tables `dbo.Food`, `dbo.Menu` and `dbo.FoodMenu` which is the many-to-many link table - like this:
* dbo.Food { ID, FoodName }
* dbo.Menu { ID, MenuName }
* dbo.FoodMenu { FoodID, MenuID }
I want to insert Food id and Menu id into FoodMenu table. My context is ok, my mapping is ok, codes and `Exception` below. Please help.
public JsonResult FoodMenu(FoodMenuViewModel vm)
{
if (ModelState.IsValid)
{
ManyDbContext ctx = new ManyDbContext();
foreach (var item in vm.MenuIds)
{
ctx.FoodMenus.Add(new FoodMenu { FoodID = vm.FoodId, MenuID = item });
ctx.SaveChanges();
}
return Json(new { Result = true, Mesaj = "" });
}
else
{
return Json(new { Result = false, Mesaj = "" });
}
}
Exception:
> System.Data.Entity.Infrastructure.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.'
> SqlException: Invalid object name '**dbo.FoodMenus**'.
Context:
public DbSet
public DbSet
ibrahim gencPosted Jul 15, 2019, 10:31 AM
ibrahim gencPosted Jul 8, 2019, 5:27 AM
public class FoodMenu
{
[Key, Column(Order = 0)]
public int FoodID { get; set; }
[Key, Column(Order = 1)]
public int MenuID { get; set; }
}
}
Madan ShekarPosted Jul 8, 2019, 5:23 AM
ibrahim gencPosted Jul 8, 2019, 5:20 AM
Madan ShekarPosted Jul 8, 2019, 5:15 AM
Madan ShekarPosted Jul 8, 2019, 5:03 AM