在这里遇到问题。
我正在为基于OData的查询开发LINQ样式机制,在特定类型中,您可以输入过滤器或扩展属性,我们可以很好地配合使用:
从类型中选择我们要选择的属性(然后扩展这些属性,即导航属性,并通过网络发送该数据。)
问题在于,当该属性是数组时,这不起作用。
我还发现,如果您仅进行扩展而不进行进一步扩展或选择,那么您会从该实体以及该实体中的实体(如果有意义)中接收到所有信息,但是由于数据量大,我们希望避免这种情况我们会做到的。
我们有这样的实体:
export interface Building {
Identity: string;
Id: number;
Name: string;
Floors?: Floor[];
Statistics?: BuildingStatistics;
}
export interface BuildingStatistics {
Id: number;
EquipmentCount: number;
FloorCount: number;
}
export interface Floor {
Id: number;
Name: string;
}
进行查询:
Building.Query()
.Filter(x =>
x.EqualsField("Id", Guid.parse(buildingID)))
.Expand(x => {
x.Expand("Statistics", x => {
x.Expand("FloorCount") ///// Works just fine
})
})
.Exec().then(x => x.value))
.pipe(map(kpiValues => this.mapKpiAPIintoKpi(kpiValues)))
}
问题在这里:
Building.Query()
.Filter(x =>
x.EqualsField("Id", Guid.parse(buildingID)))
.Expand(x => {
x.Expand("Floors", x => {
x.Expand("Name") //// "Name" is underlined" (Select or Expand doesn't matter cause instead of a string there might be a Class)
})
})
.Exec().then(x => x.value))
.pipe(map(kpiValues => this.mapKpiAPIintoKpi(kpiValues)))
}
带下划线的错误-(TS)类型“名称”的参数未分配给类型为“数字”的参数| “长度” | “ toString” |等等...还有14个等等...
这是我们的“选择并扩展”:
public Select<K extends keyof T>(select: K) {
if (this._select != '') {
this._select += ",";
}
this._select += select;
return this;
}
public Expand<K extends keyof T>(property: K, expand?: (expansion: ODataExpandBuilder<T[K]>) => void) {
var expando = new ODataExpandBuilder<T>();
if (expand != null) {
expand(expando);
}
if (this._expand != '') {
this._expand += ',';
}
this._expand += property;
let nextExpand = expando.buildUrl();
if (nextExpand != '') {
this._expand += '(' + nextExpand + ')';
}
return this;
}