以下代码运行时出现错误:
let em = new breeze.EntityManager('http://localhost/api');
let query = breeze.EntityQuery.from('Customer').where('State', '==', 'co').toType('Customer'); //error
em.executeQuery(query)
.then(data => {
//do something with data
})
.catch(error => {
//error handling
});
错误:二元谓词的左侧不能是文字表达式,它必须是有效的属性或函数谓词表达式:State
所以我将上面的代码改为如下所示,但我仍然得到同样的错误:
let em = new breeze.EntityManager('http://localhost/api');
let condition = breeze.Predicate.create('State', '==', 'co'); //added predicate
let query = breeze.EntityQuery.from('Customer').where(condition).toType('Customer'); //error
em.executeQuery(query)
.then(data => {
//do something with data
})
.catch(error => {
//error handling
});
但如果不使用toType,以下工作正常:
let em = new breeze.EntityManager('http://localhost/api');
let condition = breeze.Predicate.create('State', '==', 'co');
let query = breeze.EntityQuery.from('Customer').where(condition); //works without toType
em.executeQuery(query)
.then(data => {
//do something with data
})
.catch(error => {
//error handling
});
请告知我如何解决它。
答案 0 :(得分:0)
您可能没有正确填充元数据。请确保在使用谓词之前正确执行fetchMetadata,以查找在元数据中找不到的字段 - 很有可能。
let em = new breeze.EntityManager('http://localhost/api');
em.fetchMetadata().then(() => {
// execute your query here.
let condition = breeze.Predicate.create('State', '==', 'co'); //added predicate
let query = breeze.EntityQuery.from('Customer').where(condition).toType('Customer'); //error
em.executeQuery(query)
.then(data => {
//do something with data
})
.catch(error => {
//error handling
});
})
另请注意,如果州或客户不在正确的“案例”中,您可能会收到此信息。您可能已指定camelCase作为选项?那么这个领域应该是国家而不是国家等。