Support "Include" when using stored procedure in FromSql
See original GitHub issueSuppose we have a DTO:
public class Person
{
public string FirstName { get; set; }
public int Id { get; set; }
public string LastName { get; set; }
public Pet Pet { get; set; }
public int PetId { get; set; }
}
public class Pet
{
public int Id { get; set; }
public string Name { get; set; }
}
Currently running the code below throws “The Include operation is not supported when calling a stored procedure.”
db.Set<Person>().Include(p => p.Pet).FromSql("[dbo].[GetPersonsWithPets] @sortby = {0}", sortBy)
whereas if you use "SELECT Person.*, Pet.Name FROM Person INNER JOIN Pet on Person.PetId = Pet.Id"
, it works.
Can we get the same support for stored procedures? If they both return the same set of columns, it shouldn’t be an issue, should it?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Error when using FromSql and include ("The ...
Message: The Include operation is not supported when calling a stored procedure. Source: Microsoft.EntityFrameworkCore.Relational. enter image ...
Read more >Support "Include" when using stored procedure in FromSql
Besides that, we can make Include() work when composable SQL (i.e. SELECT) statements are passed to FromSql() by layering any necessary filters ...
Read more >Working with Stored Procedure in Entity Framework Core
Here, you will learn how to execute the database stored procedure in Entity Framework Core. EF Core provides the following methods to execute...
Read more >SQL Queries - EF Core
You can use FromSql to begin a LINQ query based on a SQL query: ... SQL queries can be used to execute a...
Read more >How to Execute Stored Procedures With EF Core 7
In this article, we are going to ;earn how to execute stored procedures in Entity Framework Core 7 with different examples.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Assuming you have two stored procedures with the same filter criteria:
when iterating over persons you will see that the references on each person point to the right pets.
BTW, with SQL Server you should be able to write queries against Table-Valued Functions as well.
But fundamentally you cannot do this with a single query.
EF will automatically wire up the references between entities that have been queried for