Javascript Breeze.js-尝试使用“时出错”;任何;运算符-错误:无法获取属性值';不寻常的';:对象为null或未定义
我试图使用Breeze中的“any”操作符来查询多个表,并得到以下错误-TypeError:无法获取属性“isAnonymous”的值:对象为null或未定义 我能找到的唯一与stackoverflow相关的问题是这个问题,但由于海报没有提供更多代码,因此没有解决isAnonymous问题的方法: 我使用微风1.4.11与 实体框架5 我尝试运行的查询是Javascript Breeze.js-尝试使用“时出错”;任何;运算符-错误:无法获取属性值';不寻常的';:对象为null或未定义,javascript,sql,breeze,durandal,hottowel,Javascript,Sql,Breeze,Durandal,Hottowel,我试图使用Breeze中的“any”操作符来查询多个表,并得到以下错误-TypeError:无法获取属性“isAnonymous”的值:对象为null或未定义 我能找到的唯一与stackoverflow相关的问题是这个问题,但由于海报没有提供更多代码,因此没有解决isAnonymous问题的方法: 我使用微风1.4.11与 实体框架5 我尝试运行的查询是 var getEntities = function (entitiesObservable) { var whereClause
var getEntities = function (entitiesObservable) {
var whereClause = "";
whereClause = Predicate.create("t_entity_nm", "any", "frst_nm", "startsWith", "Frank");
var query = EntityQuery.from("Entities")
.where(whereClause)
.expand("t_entity_nm");
$('#loading-indicator').show();
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
function querySucceeded(data) {
$('#loading-indicator').hide();
if (entitiesObservable) {
entitiesObservable(data.results);
}
log("Retrieved [Entities] from remote data source", data, true);
}
};
t\u entity
在entity\u sys\u key\u id
上连接到t\u entity\u nm
…它们是视图…以下是视图定义
CREATE VIEW [dbo].[t_entity]
( [entity_sys_key_id]
, [pers_flag]
, [dob_dt]
, [birth_plc]
, [sin]
, [hsn]
, [drv_lcnc_num]
, [ap_vndr_num]
, [ar_cstmr_num]
, [sec_grp_sys_key_id]
, [actv_flag]
, [log_eff_dt]
, [log_can_dt]
, [log_upd_by]
, [sys_del_flag]
, [sys_ts]
)
AS
SELECT
[entity_sys_key_id]
, [pers_flag]
, [dob_dt]
, [birth_plc]
, [sin]
, [hsn]
, [drv_lcnc_num]
, [ap_vndr_num]
, [ar_cstmr_num]
, [sec_grp_sys_key_id]
, [actv_flag]
, [log_eff_dt]
, [log_can_dt]
, [log_upd_by]
, [sys_del_flag]
, [sys_ts]
FROM [CMN_DEV].[dbo].[t_entity]
CREATE VIEW [dbo].[t_entity_nm]
(
[entity_nm_sys_key_id]
, [entity_sys_key_id]
, [entity_nm_typ_cd]
, [saltn_cd]
, [frst_nm]
, [mid_nm]
, [last_nm]
, [firm_nm]
, [nysiis_key]
, [prmy_flag]
, [sec_grp_sys_key_id]
, [log_eff_dt]
, [log_can_dt]
, [log_upd_by]
, [sys_del_flag]
, [sys_ts]
)
AS
SELECT
[entity_nm_sys_key_id]
, [entity_sys_key_id]
, [entity_nm_typ_cd]
, [saltn_cd]
, [frst_nm]
, [mid_nm]
, [last_nm]
, [firm_nm]
, [nysiis_key]
, [prmy_flag]
, [sec_grp_sys_key_id]
, [log_eff_dt]
, [log_can_dt]
, [log_upd_by]
, [sys_del_flag]
, [sys_ts]
FROM [CMN_DEV].[dbo].[t_entity_nm]
Breeze控制器如下所示:
namespace MarketingPromotions.Controllers
{
[BreezeController(MaxAnyAllExpressionDepth = 2)]
public class BreezeController : ApiController
{
readonly EFContextProvider<OASIS_DEVEntities> _contextProvider =
new EFContextProvider<OASIS_DEVEntities>();
[HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
#endregion
[HttpGet]
public IQueryable<t_entity> Entities()
{
return _contextProvider.Context.t_entity;
}
[HttpGet]
public IQueryable<t_entity_nm> EntityNames()
{
return _contextProvider.Context.t_entity_nm;
}
}
其中“this”是breeze.debug.js中以下代码段中的frst_nm字段:
proto._validate = function(entityType) {
// will throw if not found;
if (this.isValidated) return;
this.isValidated = true;
if (this.propertyPath) {
if (entityType.isAnonymous) return;
var prop = entityType.getProperty(this.propertyPath, true);
if (!prop) {
var msg = __formatString("Unable to resolve propertyPath. EntityType: '%1' PropertyPath: '%2'", entityType.name, this.propertyPath);
throw new Error(msg);
}
if (prop.isDataProperty) {
this.dataType = prop.dataType;
} else {
this.dataType = prop.entityType;
}
} else if (this.fnNodes) {
this.fnNodes.forEach(function(node) {
node._validate(entityType);
});
}
};
这看起来像是资源名称问题。我猜您尚未建立资源名称/实体类型映射 请看以下链接: 还有这个:
在子主题下:资源名称不是EntityType名称您是否尝试过直接对EF执行查询(应该翻译),以确定查询本身是否有效。根据您的建议,我尝试了这一方法,它确实有效[HttpGet]public IQueryable EntitiesByName(){System.Data.Entity.Infrastructure.DbQuery query=\u contextProvider.Context.t_Entity;query=query.Include(“t_Entity_nm”);return query.Where(e=>e.t_Entity_nm.Any(en=>en.frst_nm.StartsWith(“Frank”));}然后我看到了你关于资源名称/实体类型映射的另一条评论,并修复了它。你能将这个问题标记为已回答吗?(这样我就可以从列表中删除这个:)是的,非常感谢您的快速帮助!我刚刚准备了一条注释,以将其置于真实答案之下。资源名称不是EntityType名称正是我的问题。在我的例子中,资源是Entities,EntityType是t_entity当我将toType(“t_entity”)添加到查询中时,它可以工作var query=EntityQuery.from(“Entities”).toType(“t_entity”).where(where子句)。展开(“t_entity_nm”);我将尝试在metadatastore var metadatastore=manager.metadatastore;metadatastore.setEntityTypeForResourceName('Speakers','Person');在我的例子中是metadatastore.setEntityTypeForResourceName('enties','t_entity'));谢谢!我最终创建了一个在shell.js中调用的函数
函数mapEntityTypesToResourceNames(){var store=datacontext.manager.metadataStore;store.setEntityTypeForResourceName('Entities','t_entity');}
(我在durandal中使用热毛巾)在启动方法中,该方法是在激活方法中的primeData承诺返回后调用的方法。function activate(){return datacontext.primeData()。然后(boot).fail(failedInitialization);return boot();}
我们已经考虑将其作为一个标准选项。您可以在用户语音上对此投赞成票
proto._validate = function(entityType) {
// will throw if not found;
if (this.isValidated) return;
this.isValidated = true;
if (this.propertyPath) {
if (entityType.isAnonymous) return;
var prop = entityType.getProperty(this.propertyPath, true);
if (!prop) {
var msg = __formatString("Unable to resolve propertyPath. EntityType: '%1' PropertyPath: '%2'", entityType.name, this.propertyPath);
throw new Error(msg);
}
if (prop.isDataProperty) {
this.dataType = prop.dataType;
} else {
this.dataType = prop.entityType;
}
} else if (this.fnNodes) {
this.fnNodes.forEach(function(node) {
node._validate(entityType);
});
}
};