【问题标题】:Specify columns in empty IQueryable in WCF Data Service?在 WCF 数据服务的空 IQueryable 中指定列?
【发布时间】:2016-03-22 10:17:00
【问题描述】:

我有一个DataService,其中包含以下可查询:

public IQueryable<MyData> MyDataList => myDataList.AsQueryable();

我在Excel 2016 中连接到此数据服务。一切正常,但是当列表为 empty 时,我收到以下错误消息。

 The query did not run or the Data Model could not be accessed.
 Here's the error message we got:

 An Evaluate statement cannot return a table without columns

似乎客户端 (Excel) 需要一个对象来成功确定列。为什么? 是否可以在不需要对象的情况下告诉客户有关列的信息?

【问题讨论】:

  • 转载。 this 有关系吗?
  • 看起来同样的问题。确实需要某种元数据才能成功填充列。

标签: excel odata wcf-data-services


【解决方案1】:

您不能先检查结果查询以查看它是否包含任何内容并返回实际数据或默认数据吗?

  var defaultList = new List<MyData>();

public IQueryable<MyData> MyDataList = (myDataList.Any())?myDataList.AsQueryable():defaultList.AsQueryable();

【讨论】:

  • 有趣的想法;我担心它不会对接收端产生影响,让我检查一下
  • 不,它的行为完全相同(假设 myDataList 与空情况下的 List&lt;MyData&gt; 的新实例没有什么不同)。
  • 您需要将至少一个对象添加到列表中。我猜这是协议的一个弱点。
  • 如果是,那么它的设计者一定与那个认为未选中的复选框只会给 http 回发增加臃肿的人有关。
猜你喜欢
  • 2011-05-16
  • 1970-01-01
  • 2011-07-19
  • 2011-04-22
  • 1970-01-01
  • 1970-01-01
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多