-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I call a db function that returns a primitive type? #1194
Comments
Create a QueryType
And get it using FromSQL |
@ErikEJ Funny but thanks. Would be a great idea to get the results directly for primitive types. |
Yes, agree on "funny" - making it simpler is under consideration! |
For the reference, it's possible using the connection to create a command: public static async Task<T> ExecuteScalarAsync<T>(this DbContext context, string rawSql,
params object[] parameters)
{
var conn = context.Database.GetDbConnection();
using (var command = conn.CreateCommand())
{
command.CommandText = rawSql;
if (parameters != null)
foreach (var p in parameters)
command.Parameters.Add(p);
await conn.OpenAsync();
return (T)await command.ExecuteScalarAsync();
}
} Would be nice if the docs were updated to include this info and people's life easier. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to call a built-in db function that returns a
bit
, how would I achieve that?Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: