question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raw store access: Support execution of SQL that returns results but is not composable on the store, e.g. stored procedures

See original GitHub issue

We should provide a simple mechanism to execute queries/commands such as regular stored procedures that contain a SELECT statement. What FromSql() does won’t work for those because you cannot used them as sub queries.

A few things we could use:

  1. Provide an API akin FromSql() but switch composition to in-memory if subsequent LINQ operators are applied. Same warning and kill switch for query evaluation we have talked about having for other queries would apply to these.
  2. Provide a completely separate API pattern that is meant for non-composable results and even not return IEnumerable<T> but a new type that implements GetEnumerator() and AsEnumerable()
  3. Stick the stored procedure results into a table-valued variable and then keep composing as normal. This would move processing to the server and make composition more seamless but would most likely not make it any more efficient than option (1).
  4. Recognize the token “EXEC” in FromSql() (which is pretty standard although no longer required) for SQL Server as an indication that what follows is a non-composable stored procedure and that needs to go through a different execution mode (e.g. the one described in (1) or the one described in (3)).

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
verdie-gcommented, May 2, 2017

I have made this to call stored procedure and map the DataReader to a specified model. I hope it helps.

1reaction
mikarycommented, Sep 14, 2015

We don’t currently have support for named parameters in FromSql and ExecuteSqlCommand. There are plans to support other patterns in the future (i.e. SqlParameter, DbParameter, anonymous types), but for now you should be able to use the somewhat clunky pattern that we use in FromSqlSprocQuerySqlServerTest:

var userType = dbContext.Set().FromSql("dbo.SomeSproc @Id = {0}, @Name = {1}", 45, "Ada");
Read more comments on GitHub >

github_iconTop Results From Across the Web

Include with FromSqlRaw and stored procedure in EF Core ...
I am getting: FromSqlRaw or FromSqlInterpolated was called with non-composable SQL and with a query composing over it. Consider calling ...
Read more >
SQL Queries - EF Core
Using SQL queries in Entity Framework Core. ... SQL queries can be used to execute a stored procedure which returns entity data:.
Read more >
Stored Procedures with Multiple Result Sets - EF6
This article will show you two ways that you can use to access more than one result set from a stored procedure in...
Read more >
Using Stored Procedures with Return Values
In this article, we will learn how we can use a Stored Procedure with return values with all details. Introduction.
Read more >
Data definition language (DDL) statements in GoogleSQL
Data definition language (DDL) statements let you create and modify BigQuery resources using GoogleSQL query syntax. You can use DDL commands to create, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found