如何在MVVM中获得最后生成的代码

本文关键字:后生 最后 代码 MVVM | 更新日期: 2023-09-27 18:13:25

我在我的项目中使用了MVVM架构。我有ServiceLayer, ViewModel Layer, Core(Entities)WebApp。我有这个方法在Product controller:

var result = _productService.Add(productViewModel);
        switch (result)
        {
            case AddStatus.Successfull:
                _uow.SaveChanges();
            *** here I need product.Code
             //other case 
        }

和My service is:

  public AddStatus Add(AddProductViewModel productViewModel)
    {
        var productModel = Mapper.Map(productViewModel, new Product());
      _uow.MarkAsBaseAdded(productModel);
        return AddStatus.Successfull;
    }

如何在控制器中调用_uow.SaveChanges();后获得ProductCode ?

如何在MVVM中获得最后生成的代码

在_uow.SaveChanges()之后,你的模型会自动更新为新的值

我相信productModel是模型类,所以productModel。代码将给出最后插入的标识值。