Compiled models —— .NET Core 6.0

官方文档:

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/whatsnew#compiled-models

 

优势:

  • improve EF Core startup time for applications with large models.
    • Startup time means the time to perform the first operation on a DbContext when that DbContext type is used for the first time in the application. Note that just creating a DbContext instance does not cause the EF model to be initialized. Instead, typical first operations that cause the model to be initialized include calling DbContext.Add or executing the first query.
    • A large model typically means 100s to 1000s of entity types and relationships.
  • Compiled models are created using the dotnet ef command-line tool. Ensure that you have installed the latest version of the tool before continuing.
  • The --output-dir and --namespace options can be used to specify the directory and namespace into which the compiled model will be generated.
    • The output from running this command includes a piece of code to copy-and-paste into your DbContext configuration to cause EF Core to use the compiled model.
  • multiple compiled models can be generated for DbContext types that may use different models depending on some runtime configuration
  • Compiled models have some limitations:

  •  

     

posted @ 2022-01-06 18:46  PanPan003  阅读(105)  评论(0编辑  收藏  举报