-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
FromSqlRaw() doesn't work with TPT #23769
Comments
This is tracked by #21627; please vote for that issue. |
I think creating a separate C# class. is a possible workaround for some use cases. public class UserFromSql
{
public Guid Id { get; set; }
public string IdentityUserId { get; set; }
public string Name { get; set; }
public string JsonPermissions { get; set; }
} Context.Set<UserFromSql>().FromSqlRaw("select * from users"); If doing code-first then you might need to tell EF that the entity (
|
@ajcvickers Sorry for asking here but in our application, it looks like we ultimately just need an Something like this but this doesn't work ctx.Set<string>().FromSqlRaw("select id from ..."); Thanks in advance! |
@gojanpaolo that would be #11624, which isn't supported yet by EF Core. You can easily drop down to ADO.NET or use Dapper to execute that query. |
@roji thanks for the response and linking the open issue. I think I'll keep the class with a |
I'm trying to execute an SQL query using
|
It is impossible to use FromSqlRaw() when using TPT approach.
And EF configuration is next:
Now when I try to execute my code
I'm getting an error: "Using 'FromSqlRaw' on DbSet of 'User' is not supported since 'User' is part of hierarchy and does not contain a discriminator property."
After some researches, I found that plain Linq and FromSqlRaw() method handle discriminator identifying in different ways. For regular Linq exists 'else' statement which joins tables to get discriminator (Image) value, while FromSqlRaw() only throws an exception when no discriminator us declared (Image)
The text was updated successfully, but these errors were encountered: