From 093c663b31c8b01d730f09154506c7a2ee34cd9b Mon Sep 17 00:00:00 2001 From: Kevin Matsubara Date: Tue, 8 Apr 2025 22:24:28 +0200 Subject: [PATCH] Add example scalar query. --- EntityFrameworkCore.Console/Program.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/EntityFrameworkCore.Console/Program.cs b/EntityFrameworkCore.Console/Program.cs index 15fd78f..e9552a6 100644 --- a/EntityFrameworkCore.Console/Program.cs +++ b/EntityFrameworkCore.Console/Program.cs @@ -16,7 +16,17 @@ context.Database.EnsureCreated(); // Rather than raise: "System.InvalidOperationException: Sequence contains no elements." // var firstCoach = await context.Coaches.FirstOrDefaultAsync(); -await RawSQLStatement(); + + +async Task QueryScalarType() +{ + // Query a scalar or non-entity type. + // Scalar subqueries or scalar queries are queries that return exactly one column and one or zero records. + // Source: https://stackoverflow.com/questions/20424966/what-is-a-scalar-query + var leagueIds = context.Database.SqlQuery( + $"SELECT Id FROM Leagues" + ).ToList(); +} async Task RawSQLStatement() {