这条简单的 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]获取计数的索引