简体   繁体   中英

ASP.NET Core 6.0 Counting

Hay Im working on a project for my exam in C# and ASP.NET Core 6.0 , the teachers want me to count every sign up on a tournament.

(little more information; Its a tournement website and the database has 2 tables for this. Tournament and Sign Ups. So they want me to count every sign up in the table Sign Ups with the same TournamentID.)

I dont know how to do this, well i know that i need to use a Count method.

My toughts:

Count list where _context.Tournament.TournamentID == _context.SignUps.TournamentID

I dont know how to put this in a code. Can someone help me?

**Edit 1:

Btw, this is a code i tried, but it dont work.

var count = _context.Signups.Count(t => t.TournamentId == id);
            ViewBag.CountingSingups = count;

By following this condition you will get count of Signups for each tournament individually.

var count = _context.Signups.GroupBy(gp => gp.TournamentID ).Select(y => new
                {
                    TournamentID = y.Key,
                    CoutOfusers=y.Count()
                 }).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM