Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@Dezzzu
Copy link

Dezzzu commented Apr 24, 2020

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

[Owned]
public class GeoPoint 
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }
}

Other properties are irrelevant to the issue I'm dealing with.

public class Photo
{
    public GeoPoint PlaceTaken { get; set; }
}

The database is created using migrations just fine, the stored procedure itself works as intended (tried from SSMS).
Then I call the procedure:

public IEnumerable<Photo> GetByUserIdAndKeyword(int userId, string keyword)
{
    return Context.Set<Photo>().FromSqlInterpolated($"exec GetUserPhotosByKeyword {userId}, {keyword}");
}

And that's what I get

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

@smitpatel
Copy link
Contributor

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.

@Dezzzu
Copy link
Author

Dezzzu commented Apr 24, 2020

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?

@smitpatel
Copy link
Contributor

See #14525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants