-
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
Tpt mapping Sql Query #29687
Comments
This is likely because of #29642; in other words, it's a bug (rather than an actual change) that will likely be fixed soon in 7.0. By itself, this shouldn't be a reason to need compiled models. Apart from that, you posted above about several unrelated things...
Performance-wise, this is certainly the worse of the three inheritance mapping strategies, so we generally discourage using it. See these docs for more details.
Can you provide more details on what that means exactly?
Your query requests all Pets: IQueryable<Pet> petQuery = context.Set<Pet>().Where(p => p.Name == "Cat 1"); Since Cats and Dogs are subtypes of Pet, EF fetches them. Think of it as if |
Yes, you are right, so can we make an extension method like But we cannot achieve something like this if we cannot make query filters on subtypes! Now, we close this issue waiting for #29642
I want to use Query Filters in authorization, but I cannot make Query Filter (in our example) separately for Cat and Dog entities. |
You can already query only for Pet instances (since Pet isn't abstract), and exclude Dogs and Cats; see these docs. If you just want only a certain set of properties, project those out as an anonymous type; that should only query the tables it requires: context.Set<Pet>().Select(p => new { p.Prop1, p.Prop2 }
That's #10259. |
Can anyone please explain why EF trying to tell the whole story of the entity!
I believe that TPT mapping strategy is the most widely used in real world applications, so this strategy deserves a lot of support and development.
EF team is a great and does a lot of effort introducing new features. Unfortunately, this is done before completing what is required for the existing features.
for example. Because I use TPT strategy I can't use Query Filters usefully.
As another example, I am working on a multimodule multitenant application that contains more than 250 Entities. After upgrading to version 7, creating the model takes 10 times the time that was required for version 6. So, I studied the possibility of using Compiled Model, but unfortunately there is a conflict with the most important feature that I use in EF which is IModelCacheKeyFactory because the application has more than one model depending on the module selected by the tenant.
The question:
Regarding the following code:
Why EF tries to get the whole hierarchy while i just request a top-level entity?
I didn't make a request for any property from Cat or Dog models, I just want the Pet object.
This example has a second problem with the generated SQL string for delete Pet object, it generates multiple Delete statements even if I set delete cascading to Cascade not ClientCascade.
I modified the Cascading behavior after upgrading to Version 7 in response for https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes#tpt-cascade-delete
Thanks.
Project
Code
Output
Include provider and version information
EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.Sqlite)
Target framework: (e.g. .NET 7.0)
Operating system: Windows 10
IDE: (e.g. Visual Studio 2022 17.4)
The text was updated successfully, but these errors were encountered: