考虑这个breze查询:
return EntityQuery.from('myAPI')
.noTracking(true)
.using(manager).execute()
.then(querySucceeded)
.fail(queryFailed);
我的API定义如下:
[HttpGet]
public object myAPI()
{
// var userId = get the users id from auth ticket
var userPref = _contextProvider.Context.UserPreferences.Where(u => u.userId == userId);
var userOptions = _contextProvider.Context.UserOptions.Where(u => u.userId == userId);
return new
{
userPref,
userOptions
};
}
我知道我可以访问原始数据,这很棒。但除此之外,实体是在实体管理器中创建的,我希望它们不是。这适用于返回IQueryable的api。对于返回多个结果集的web apis,noTracking是否有不同的语法?
谢谢
答案 0 :(得分:1)
我无法重现您描述的错误。我有a similar DocCode test that passes引用了Breeze v1.5.3。
以下是pertinent NorthwindController method:
[HttpGet]
public object Lookups()
{
var regions = _repository.Regions;
var territories = _repository.Territories;
var categories = _repository.Categories;
var lookups = new { regions, territories, categories };
return lookups;
}
这是通过的QUnit测试:
asyncTest('object query (e.g., lookups) w/ "no tracking" does not add to cache', function () {
expect(2);
var em = newNorthwindEm();
EntityQuery.from('Lookups')
.noTracking(true)
.using(em).execute()
.then(success).fail(handleFail).fin(start);
function success(data) {
var lookups = data.results[0];
var hasLookups = lookups &&
lookups.categories && lookups.regions && lookups.territories;
ok(hasLookups, 'Expected a lookups object w/ categories, regions and territories');
var cached = em.getEntities();
var len = cached.length;
equal(0, len, 'Expected ZERO cached entities of any kind and got ' + len);
}
});
如果我注释掉noTracking(true)
子句,测试失败并告诉我缓存中有65个实体......正如预测的那样。
我错过了什么?