You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FromSqlInterpolated throws System.InvalidOperationException when calling to a stored procedure which returns an Entity containing an [Owned] property
#20743
Closed
Dezzzu opened this issue
Apr 24, 2020
· 3 comments
So I have an entity Photo, which among other properties contains a property of owned model GeoPoint. Also, I have a stored procedure which selects all Photos with some condition. After I call the procedure with FromSqlInterpolated (on top of set of Photos), I have a System.InvalidOperationException thrown. I'm suggested to use AsEnumerable() right after calling the procedure, but adding that doesn't change anything and throws the same error. It doesn't happen if I change the [Owned] model to be an ordinary one.
System.InvalidOperationException : FromSqlRaw or FromSqlInterpolated was called with non-composable SQL and with a query composing over it. Consider calling `AsEnumerable` after the FromSqlRaw or FromSqlInterpolated method to perform the composition on the client side.
If I get rid of [Owned] attribute and create a distinct DB table for GeoPoints with mapping to point's Id from Photo, everything works fine.
Further technical details
EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.1
Operating system: Windows 10
IDE: JetBrains Rider 2020.1
The text was updated successfully, but these errors were encountered:
Owned entities are auto-included by EF Core when querying for owner. Hence, we need to generate a join with the SQL you provided which is not going to work since it is sproc.
Yeah, that's exactly what I imagined. I'm okay with the GeoPoint being not owned, but isn't there any way you could make this work in further releases?
So I have an entity Photo, which among other properties contains a property of owned model GeoPoint. Also, I have a stored procedure which selects all Photos with some condition. After I call the procedure with FromSqlInterpolated (on top of set of Photos), I have a System.InvalidOperationException thrown. I'm suggested to use AsEnumerable() right after calling the procedure, but adding that doesn't change anything and throws the same error. It doesn't happen if I change the [Owned] model to be an ordinary one.
Steps to reproduce
Other properties are irrelevant to the issue I'm dealing with.
The database is created using migrations just fine, the stored procedure itself works as intended (tried from SSMS).
Then I call the procedure:
And that's what I get
If I get rid of [Owned] attribute and create a distinct DB table for GeoPoints with mapping to point's Id from Photo, everything works fine.
Further technical details
EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.1
Operating system: Windows 10
IDE: JetBrains Rider 2020.1
The text was updated successfully, but these errors were encountered: