I have this table DDL:
CREATE TABLE [dbo].[Audit]
(
[AuditId] INT IDENTITY (1, 1) NOT NULL,
[Entity] INT NOT NULL,
[UserId] INT NOT NULL,
[Note] VARCHAR(200) NULL,
[Date] DATETIME NOT NULL,
[Action] INT NOT NULL,
CONSTRAINT [PK_Audit]
PRIMARY KEY CLUSTERED ([AuditId] ASC)
);
What I would like to do is to get a report that shows something like this:
UserId Action Count
---------------------
user1 Insert 25
user1 Update 30
User1 Delete 45
I have been using Entity Framework for my queries like this:
var result = db.Audits
.Where(a => a.UserId == userId)
.OrderByDescending(a => a.AuditId)
.ToList();
return Ok(result);
Can someone tell me: is it possible to get the kind of report that I need with EF or do I need to resort to a SQL statement and then somehow get the output of that?