如何在MVVM中获取上次生成的代码

时间:2016-10-18 08:29:20

标签: c# mvvm

我在“我的项目”中使用了MVVM架构。 我有ServiceLayerViewModel LayerCore(Entities)WebApp。 我在Product controller中有这个方法:

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

我的服务是:

  public AddStatus Add(AddProductViewModel productViewModel)
    {

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

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

1 个答案:

答案 0 :(得分:1)

在_uow.SaveChanges()之后,您的模型会自动使用新值进行更新。

我相信productModel是模型类,因此productModel.code将给出最后一个被识别的身份值。