Cosmos: remove automatic composition of discriminator filter in raw SQL queries
See original GitHub issueTo ensure the correct type is project for materialization, FromSqlRaw
wraps the query passed, so that this:
var contacts = await context.Contacts.FromSqlRaw("select * from Contacts").ToListAsync();
Really gets resolved as this:
SELECT c FROM (SELECT * From Contacts) c WHERE c.Discriminator = "Contact"
While this works fine in most scenarios, it causes issues when users project explicit columns. Although this works fine as a raw query and returns multiple records:
SELECT Id, Name, Phone, Address FROM Contacts
This will never return any records and doesn’t throw an error or log a warning:
var contacts = await context.Contacts.FromSqlRaw("select Id, Name, Phone, Address from Contacts").ToListAsync();
Although this behavior is documented, it’s not obvious if the documentation hasn’t been read. It could lead to a lot of troubleshooting around a non-issue that just requires the user add one column to their select statement.
I suggest either logging a warning or throwing an exception when Discriminator isn’t included so it’s clear to the user it won’t behave as expected and what to do for mitigation.
EF Core version: EF Core 6.0 Database provider: All Target framework: .NET 6.0 Operating system: BeOS IDE: Visual Studio 2022
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (16 by maintainers)
@roji Nominating you to do this for 6.0. 😃
Yes, otherwise it would be a “breaking” change