0

我是 Breeze 的新手,我正在尝试使用 Breeze Angular 和 WebApi 构建示例应用程序。我面临一个问题,我需要使用新添加的对象SaveResult更新本地数组(Angular) 。服务器代码

    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {
        return  context.SaveChanges(saveBundle);
    }

客户代码

$scope.AddNewProduct = function () {
       if ($scope.Product !== null) {
        datacontext.addNew($scope.Product, function (newProduct) {
            $scope.Products.unshift(newProduct);
            $scope.$apply();
        });
    }
};

它不工作。它用空值更新 UI

根据微风演示应用程序,我的 WebApi 中有三种方法。

namespace AngularWebApi.ApiControllers
{
[BreezeController]
public class ProductsBreezeController : ApiController
{
    private readonly ProductRepository context;

    public ProductsBreezeController()
    {
        context = new ProductRepository();
    }

    [HttpGet]
    public string Metadata()
    {
        return context.Metadata();
    }

    //// GET api/productsbreeze
    [HttpGet]
    public IQueryable<Product> GetAllProducts()
    {
        return context.TodoLists;
    }

    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {
        return  context.SaveChanges(saveBundle);
    }
}

public class ProductRepository : EFContextProvider<SampleEntities>
{
    public DbQuery<Product> TodoLists
    {
        get { return Context.Products; }
    }
}

}

现在GetAllProducts将此作为单个实体返回

$$hashKey: "004"
_backingStore: Object
entityAspect: ctor
maxUnits: (...)
productId: (...)
productName: (...)
__proto__: Object

但 SaveChanges 方法返回

_backingStore: Object
entityAspect: ctor
maxUnits: (...)
productId: (...)
productName: (...)
__proto__: Object

缺少$$hashKey: SaveChanges 方法中的“004”属性。我不知道在那种情况下该怎么做。

4

0 回答 0