J'ai une table:LINQ somme de sélection de requête compilé plusieurs colonnes
ForObjectTypeID (short, PK)
ForObjectID (int, PK)
UserID (int, PK)
Upvote (bool)
ShadowBannedVote (bool)
Étant donnée une, je souhaite ObjectTypeID
et ObjectID
retourner un Tuple<int, int, int>
où les valeurs respectives sont les suivantes:
- Total des votes: Nombre total d'enregistrements où
ShadowBannedVote == false
- Total des Upvotes: Nombre total d'enregistrements où
Upvote == true && ShadowBannedVote == false
- totale Ombre Banned Votes: Nombre total d'enregistrements où
ShadowBannedVote == true
Il doit être une seule requête compilée, pas fractionnés en plusieurs requêtes. C'est aussi loin que je l'ai eu, je ne peux pas calculer comment effectuer les sommes et les comptes dans la valeur de retour.
public static readonly Func<DBContext, ObjectType, int, Tuple<int, int, int>> GetTotalVotes = CompiledQuery.Compile(
(DBContext db, ObjectType forObjectType, int forObjectID) =>
db.UserVotes.Where(c => c.ForObjectTypeID == (short)forObjectType && c.ForObjectID == forObjectID)
.Select(c=> new {c.Upvote, c.ShadowBannedVote}).Select(c=> new Tuple<int, int, in>(0, 0, 0)));