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

Add precompiled query generation to the dbcontext optimize command #33747

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AndriySvyryd
Copy link
Member

@AndriySvyryd AndriySvyryd commented May 17, 2024

Also adds publish integration for precompiled queries and combines it with compiled model generation.

For the compiled model and precompiled queries to be generated when publishing with NativeAOT the only action needed is to reference Microsoft.EntityFrameworkCore.Tasks from all projects containing a DbContext or a query.

For solutions where specifying the startup project is necessary, EFStartupProject should be set.

EFOptimizeContext can be set to true to enable code generation outside of NativeAOT.

EFScaffoldModelStage and EFPrecompileQueriesStage can be set to either publish or build to control at what stage will the code be generated. Any other value will disable the corresponding generation (in case the code is generated manually using dotnet ef dbcontext optimize)

If there's more than one context and DbContextName is not set, then the compiled model will be generated for all of them.

EFTargetNamespace and EFOutputDir can be used to further fine-tune the generation.

Fixes #33103
Fixes #33558

@AndriySvyryd AndriySvyryd requested a review from roji May 17, 2024 22:49
@AndriySvyryd AndriySvyryd force-pushed the Issue33103 branch 2 times, most recently from 881f8e9 to b840cc6 Compare May 21, 2024 01:07
@AndriySvyryd AndriySvyryd marked this pull request as ready for review May 21, 2024 01:07
@AndriySvyryd AndriySvyryd force-pushed the Issue33103 branch 4 times, most recently from 620a708 to 0eaf687 Compare May 24, 2024 23:17
Condition="'$(PublishAot)'=='true'"
Properties="Configuration=$(Configuration);Platform=$(Platform);EFOptimizeContext=false;PublishAot=false" />
Properties="Configuration=$(Configuration);Platform=$(Platform);PublishAot=false;_EFGenerationStage=$(_EFGenerationStage)" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to always pass Configuration and Platform? Should we pass other properties?

This target has the same Inputs and Outputs as CoreCompile to run only if CoreCompile isn't going to be skipped -->
<Target Name="_EFPrepareForCompile"
DependsOnTargets="_EFProcessGeneratedFiles"
Condition="'$(EFOptimizeContext)'=='true'"
Condition="'$(_EFGenerationStage)'==''"
Inputs="$(MSBuildAllProjects);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way of determining whether CoreCompile is going to be skipped other than duplicating its inputs and outputs?


MSBuildLocator.RegisterDefaults();
// TODO: pass through properties
var workspace = MSBuildWorkspace.Create();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What properties should we pass through from the MsBuild invocation?

@AndriySvyryd AndriySvyryd force-pushed the Issue33103 branch 2 times, most recently from 3616c0f to 3d181c1 Compare May 31, 2024 21:00
@roji
Copy link
Member

roji commented May 31, 2024

Just to say that this is on my list to review... Will work up to it in the next few days.

@AndriySvyryd
Copy link
Member Author

Just to say that this is on my list to review... Will work up to it in the next few days.

Ok. Just note that the longer you take to review the more code will need to be reviewed 😉

@roji
Copy link
Member

roji commented May 31, 2024

That's a pretty effective way to speed up a code review :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants