-
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
Entity with OwnsOne property providing not optimal SQL #20763
Comments
@iuridosanjos This looks like a duplicate of #18299, which has been fixed in EF Core 5.0 preview 3. Can you try preview 3 and report back if it does not fix the issues you are seeing? |
@ajcvickers I've tested on the EF Core 5.0 preview 3 you've said and it's fixed. The SQL is not making unnecessary JOINs, the result of the above example is only one simple SELECT. Thanks. |
Any plans of putting this fix on EF core 3.1 |
That works for me! |
Database entities
DbContext
Problem
When I load all the Costumers from the Database, it runs the following SQL:
Note the unneeded and undesired nested select just to get Address properties. I want EF Core to load all of Address properties as if Address could not be null (the internal properties could be null, but not Customer.Addresss), but OwnedNavigationBuilder<TEntity, TRelatedEntity> don't have anything like "IsRequired" (for the Customer.Address property). How can I do that?
The SQL should look like this:
That way, I wanted to always create and "new Address()" with those results.
Can I change anything in my model configuration to tell EF Core to behave like this?
Note
This case is just an example, but shows exactly the problem I'm having in my product. The basic difference is that I'm using the Owned class for multiple properties, same as if the shown example used like 5 to 10 properties of that type (not collection). The SQL that EF Core is executing is not good and it's performancing poorly than we expected it should.
Technical Information
EF Core Version tested here: 3.1.3
SQL Server Version: SQL Server 2019
Using .NET Core 3.1
The text was updated successfully, but these errors were encountered: