title: How to call a stored procedure in EF Core 3.0 via FromSqlRaw
body: <p>I recently migrated from EF Core 2.2 to EF Core 3.0. </p>
  
  <p>Unfortunately, I haven't found a way to call a stored procedure that returns an entity. </p>
  
  <p>In EF Core 2.0 it was possible:</p>
  
  <pre><code>var spParams = new object[] { "bla", "xx" };
  var createdPath = ModelContext.Paths.FromSql("AddNodeWithPathProc  @p0, @p1", spParams).Single();
  </code></pre>
  
  <p>In EF Core 3.0 the method <code>FromSQL</code> is replaced with <code>FromSqlRaw</code>. However, I didn't manage to successfully call a stored procedure and then process the value. This is useful when the stored procedure inserts data into the database. </p>
  
  <p>So in EF Core 3.0, I use this code:</p>
  
  <pre><code>var createdPath = ModelContext.Paths.FromSqlRaw("AddNodeWithPathProc @p0, @p1", spParams).Single();
  </code></pre>
  
  <p>but it will throw an exception, because the generated SQL is invalid and looks something like this: </p>
  
  <pre><code>exec sp_executesql N'SELECT TOP(2) [p].[PathId], [p].[Level], [p].[NodeId], [p].[NodePath], [p].[NodePathString]
  FROM (
       @sql @p0, @p1
  ) AS [p]',N'@p0 nvarchar(4000),@p1 nvarchar(4000), @sql nvarchar(100)',@p0=N'1a',@p1=N'', @sql=N'AddNodeWithPathProc'
  </code></pre>
  
  <p>I tried quite a few variations, but without success. </p>
  
  <p>I'm starting to think that it is not possible to run stored procedures with <code>ModelContext.[IQueryable].FromSqlRaw</code>. In my opinion this kind defeats one of the major reasons for <code>FromSqlRaw</code> because, for normal select statements, LINQ is normally good enough. </p>
  
  <p>Does anyone know how to use stored procedures in combination with <code>FromSqlRaw</code> in EF Core 3.0? Any help is greatly appreciated.</p>
  
  <p>Thanks in advance</p>
  
  <p>PS: I know you can execute a stored procedure with <code>this.Database.ExecuteSqlRaw(SQL, parameters)</code>. However, that way it is not possible retrieve any entities that the stored procedure queries.</p>