Hi,@Gary Paquette. Welcome to Microsoft Q&A. Optimization
1.For only part of the query available use AsNoTracking().
var items = EFDbContext.MyDbSet.AsNoTracking().ToList();
2.Use Ngen to install and generate a local image of EF.
a. Open a cmd window.
b. Switch to the bin directory of the program, such as: cd d:\website\bin.
c. Run the ngen command.
For 32 bit run:
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\ngen install EntityFramework.SqlServer.dll
For 64 bit run:
%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\ngen install EntityFramework.SqlServer.dll
3.Disabling the first EF query on the table __MigrationHistory(For Code first projects).
Add code
Database.SetInitializer<EFDbContext>(null);
EFDbContext is the EF context class of my project. You need to replace it with your own EF context class according to your project.
4.EF Pre-Generated Mapping Views.
Add code
using (var dbcontext = new EFDbContext())
{
var objectContext = ((IObjectContextAdapter)dbcontext).ObjectContext;
var mappingCollection = (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
mappingCollection.GenerateViews(new List<EdmSchemaError>());
}
5.If access becomes slow after a period of time, you could set the "idle timeout" of the application to make it longer. Or you could create a scheduled task to use EF regularly.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.