Reputation: 31
I have stored procedure which loads events and their locations but when i try to call it from my Repository class using FromSql method I only get list of Event entities but locations aren't included. I tried to add Include method to my query but I got an exception that says Inclued can't be used when calling stored procedure... Is there any way to do it or i have to manually map all properties?
My SP:
ALTER PROCEDURE [dbo].[GetEventsByDistance]
@Latitude float,
@Longitude float,
@Radius int
AS
with MyCte as
(
select dbo.fnCalcDistanceKM(l.Latitude, l.Longitude, @Latitude, @Longitude) as distance, a.*, l.*
from dbo.Events a
JOIN Locations as l ON l.IdLocation = a.LocationId
)
SELECT
*
From MyCte
where distance < @Radius
RETURN
and my C# code
public async Task<List<Event>> GetEventsByDistance(string latitude, string longitude, int radiusInKm)
{
var events = new List<Akce>();
using (var context = _factory.CreateDbContext(null))
{
events = await context.Akce.FromSql($"{Constants.DB_PROC_GetEventsByDistance} {latitude}, {longitude}, {radiusInKm}").ToListAsync();
}
return events;
}
Upvotes: 2
Views: 2350
Reputation: 93
Here is related issue https://github.com/aspnet/EntityFrameworkCore/issues/3502 If you use sql function instead of stored procedure it will work with Include
Upvotes: 2