2012-03-09 27 views
0

這一件簡單的SQL的工作在SQL Server的完美......EntityDataSource的CommandText計數錯誤

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] 

顯然,簡單的東西...

UPDATE

問題由維克拉姆解決。

使用select 計數()並獲得計數值的指數與計數[0]

回答

1

添加VALUE到嵌套SELECT返回的Int32的列表來代替。

綁定這樣,返回值:

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

我記得那個試圖和我 - System.Data.Objects.MaterializedDataRecord – Luckyl337 2012-03-09 11:51:56

+0

你能告訴我你在哪裏使用計數的代碼[0]?我已經編輯了我的答案 – Vikram 2012-03-09 12:03:03