这对我来说有点神秘。我在客户端上定义了一个自定义类型,如下所示:
var store = manager.metadataStore;
store.addEntityType({
shortName: "ItemContainer",
autoGeneratedKeyType: AutoGeneratedKeyType.Identity,
dataProperties: {
id: { dataType: DataType.Int32, isNullable: false, isPartOfKey: true },
type: { dataType: DataType.Int32, isNullable: false },
isViewed: { dataType: DataType.Boolean, isNullable: false },
itemCount: { dataType: DataType.Int32, isNullable: false }
}
});
store.setEntityTypeForResourceName('Container', 'ItemContainer');
这是从服务器作为匿名类型(提琴手)传递的内容:
[{"$id":"1","$type":"<>f__AnonymousType1`4[[System.Int32,mscorlib],
[System.Int32, mscorlib],
[System.Boolean, mscorlib],
[System.Int32, mscorlib]], XYZ",
"Id":43,"Type":1,"IsViewed":true,"ItemCount":19}]
当我通过微风查询在客户端检查返回的结果时,除了 itemCount 之外,所有数据都是正确的。生成该类型的服务器代码如下所示:
var c = Items.GroupBy(x => new { x.Item.ItemTypeID, x.IsViewed })
.Select(g => new { Id = ID, Type = g.Key.ItemTypeID, IsViewed = g.Key.IsViewed, ItemCount = g.Count() });
g.Count() (LINQ 计数方法)似乎是这里的罪魁祸首。如果我传递一个普通整数,它就可以正常工作。也许这个函数被懒惰地评估了,而微风没有在正确的时间获得价值?
谢谢