1

模型(多对多关系的暴露映射表):

 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);

远程查询返回一个用户实体数组,我相信这是正确的。将“selectStr”修改为“bla”之类的无效类型会按预期抛出异常。结果:

data.results = [{"User": {...}}, {"User": {...}}] 

本地查询只是忽略选择并返回 TeamUser 结果数组:

res=[{ Here are the fields of TeamUsers }, { Here are the fields of TeamUsers }]

将“selectStr”修改为“bla”等无效类型不会引发异常。为什么省略了select,应该是这样的吗?

4

1 回答 1

3

从 v 0.74.3 开始,这应该是固定的;ie select 子句现在将被本地查询和远程查询正确解释。希望这可以帮助。

于 2012-12-06T23:36:34.080 回答