模型(用于多对多关系的公开映射表):
public class TeamUsers
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long TeamUsersId { get; set; }
public Team Team { get; set; }
public User User { get; set; }
public bool Temporary { get; set; }
}
远程和本地查询的两种常规方法:
getAllOfTypeSelectRemote = function (manager, success, failed, resource, orderBy, predicate, select) {
var query = EntityQuery
.from(resource)
.where(predicate)
.using(manager)
.select(select) //<------
.orderBy(orderBy);
return query.execute()
.then(success)
.fail(failed);
},
getAllOfTypeSelectLocally = function (manager, resource, orderBy, predicate, select) {
var res = null;
try {
res = EntityQuery
.from(resource)
.where(predicate)
.select(select) //<-----
.orderBy(orderBy)
.using(manager)
.executeLocally();
} catch (e) {
logger.error('resource: ' + resource + '<br>select: ' + select + '<br>orderBy:' + orderBy, 'Local query failed!');
}
return res;
};
这样叫:
var selectStr = 'User'; //<------
var p1 = new breeze.Predicate("Team.TeamName", Qop.Equals, team);
var p2 = breeze.Predicate("User.UserName", Qop.NotEquals, username);
var predicate = p1.and(p2);
//var res = dsUtils.getAllOfTypeSelectRemote(manager, success, queryFailed, 'TeamUsers', 'User.Nachname, User.Vorname', p1, select);
var res = dsUtils.getAllOfTypeSelectLocally(manager, 'TeamUsers', 'User.Nachname, User.Vorname', p1, selectStr);
远程查询返回一个User-Entities数组,我相信这是正确的。将'selectStr'修改为无效类型(如'bla')会按预期引发异常。 结果:
data.results = [{"User": {...}}, {"User": {...}}]
本地查询只是忽略了select并返回一个TeamUser数组 结果:
res=[{ Here are the fields of TeamUsers }, { Here are the fields of TeamUsers }]
将'selectStr'修改为像'bla'这样的无效类型会抛出NO异常。 为什么选择省略,这应该是那样的吗?
答案 0 :(得分:3)
从v 0.74.3开始,这应该是固定的;现在,本地查询以及远程查询将正确解释select子句。希望这可以帮助。