0

当我调用如下所示的函数时发生错误:

存储更新、插入或删除语句影响了意外数量的行 (0)。自加载实体后,实体可能已被修改或删除。刷新 ObjectStateManager 条目。”

功能:

[HttpPost]
public ActionResult Index(InsertPo model)
{
        var context = new UsersContext();
        var po = new Po();
        var user = new User();
        po.PoId = 12;
        po.PoNumber = model.Po.PoNumber;
        po.Style = model.Po.Style;
        po.Quantity = model.Po.Quantity;
        po.Status = "hhh";
        po.OrderDate = Convert.ToDateTime("30-12-2011");
        po.ShipmentDate = Convert.ToDateTime("2-12-2011");
        po.ProductionRate = 10;
        po.UserId = 2;

        /*buyer.BuyerName = model.Buyer.BuyerName;*/
        /* buyer.BuyerId = 1;
         buyer.PoId = 10;*/
        context.Pos.Add(po);
        context.SaveChanges();
        return RedirectToAction("Index");
}
4

1 回答 1

0

尝试将此行放在您的 Action 方法之外。

    var context = new UsersContext();
于 2013-06-02T21:29:58.343 回答