2012-02-24 1 views

Répondre

0

Vous pouvez réécrire votre requête comme ceci:

SELECT A.categoryname, COUNT(B.categoryid) AS TOT 
FROM category A LEFT OUTER JOIN items B ON A.categoryid = B.categoryid 
GROUP BY A.id, A.categoryname 

Si aucune catégorie ont le même nom, vous pouvez omettre la colonne A.id.

Ensuite, utilisez SubSonic similaire à ceci (la syntaxe exacte peut varier ...):

DAL.DB.Select(
    Aggregate.GroupBy(DAL.A.categorynameColumn), 
    Aggregate.GroupBy(DAL.A.idColumn) 
    Aggregate.Count(DAL.B.categoryidColumn, "Tot") 
    ) 
.From<DAL.A>().LeftOuterJoin(DAL.B.categoryidColumn, DAL.A.categoryidColumn)