EntityDataSource CommandText计数错误

时间:2012-03-09 11:02:14

标签: sql sql-server entitydatasource

这个简单的sql在sql server中运行得很完美......

Select it.Id as Id, it.Status as Status,
    (SELECT COUNT (*) FROM PickLocations as pl WHERE pl.PickBatchItemId = bi.Id) AS Counts
FROM PickBatches AS it
INNER JOIN PickBatchItems as bi ON it.Id = bi.PickBatchId

给我......

Id, Status, Counts
-------------------
1    1       2
2    1       0
3    2       2

但是在做出改变以致它不会抱怨......

Select it.Id as Id, it.Status as Status,
    (SELECT COUNT (pl.Id) FROM PickLocations AS pl WHERE bi.Id == pc.PickBatchItemId) AS Count
FROM PickBatches AS it
INNER JOIN PickBatchItems as bi ON it.Id == bi.PickBatchId

当我在EntityDataSource CommandText中使用它时,我得到了......

Id, Status, Counts
-------------------
1    1       System.Collections.Generic.List`1[System.Data.Common.DbDataRecord]
2    1       System.Collections.Generic.List`1[System.Data.Common.DbDataRecord]
3    2       System.Collections.Generic.List`1[System.Data.Common.DbDataRecord]

显然缺少一些简单的东西......

更新

维克拉姆解决了问题。

使用选择 count()并使用 Count [0] 获取计数索引

1 个答案:

答案 0 :(得分:1)

VALUE 添加到嵌套的SELECT会返回一个Int32列表。

像这样绑定,返回值:

Count='<%# Eval("Count[0]") %>'