我有一个带有查找功能的breeze web api控制器,可以返回不同的用户数据集。这适用于远程查询,但不适用于始终选择第一个数据集的本地查询。我的WebAPI控制器:
[HttpGet]
public async Task<object> Lookups()
{
var currentUser = await UserManager.FindById(Guid.Parse(User.Identity.GetUserId()));
var companyId = currentUser.CompanyId.Value;
return new
{
allUsersInCompany = UnitOfWork.UserRepository.Get(u => u.CompanyId == companyId && u.Enabled == true).Select(v => new User()
{
Id = v.Id,
FirstName = v.FirstName,
LastName = v.LastName,
}),
assessors = UnitOfWork.UserRepository.Get(u => u.CompanyId == companyId && u.Enabled == true && u.Id != currentUser.Id &&
(!string.IsNullOrEmpty(u.StId) || u.UserRoles.Any(ur => ur.Role.Description == "Assessor"))
).Select(v => new User()
{
Id = v.Id,
FirstName = v.FirstName,
LastName = v.LastName,
Town = v.Town,
Postcode = v.Postcode
})
};
}
然后我使用以下方法从客户端上的本地存储重建数据:
data = store.getItem("EmCache");
modelService.configureMetadataStore(em.metadataStore); }
em.importEntities(data);
_lookups = [{
allUsersInCompany: em.executeQueryLocally(_lookupsQuery.toType(em.metadataStore.getEntityType("User"))),
assessors: em.executeQueryLocally(_lookupsQuery.toType(em.metadataStore.getEntityType("User")))
}];
问题是,当我在本地执行查询时,评估者和allUsersInCompany都被设置为allUsersInCompany的数据。有没有办法为查询查询的每个部分提取正确的数据?
答案 0 :(得分:0)
您的查询将它们映射到相同的类型 -
allUsersInCompany: em.executeQueryLocally(_lookupsQuery.toType(em.metadataStore.getEntityType("User"))),
assessors: em.executeQueryLocally(_lookupsQuery.toType(em.metadataStore.getEntityType("User")))
User
的可能是为什么它抓取相同的数据。我不确定Assessors
的实体类型是什么,但是如果这是他们在数据库中调用的内容,请尝试将其更改为类似的内容 -
allUsersInCompany: em.executeQueryLocally(_lookupsQuery.toType(em.metadataStore.getEntityType("User"))),
assessors: em.executeQueryLocally(_lookupsQuery.toType(em.metadataStore.getEntityType("Assessor")))