Entity Framework 6.2 very slow first startup and EFInteractiveViews

asp.net-mvc entity-framework entity-framework-6 linq-to-entities

Expert Answer

I want to know if these issues are updated in EF 6.2.0 or method of fixing it has changed, or any thing im doing wrong/should check.

The answer is yes,

A Model Cache was added in EF 6.2.

public class MyDbConfiguration : DbConfiguration
{
    public MyDbConfiguration() : base()
    {
        var path = Path.GetDirectoryName(this.GetType().Assembly.Location);
        SetModelStore(new DefaultDbModelStore(path));
    }
}

[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyContextContext : DbContext 
{
}

Click here for additional information: https://codeopinion.com/entity-framework-code-first-model-cache/

2
1/30/2019 2:07:17 AM

Popular Answer

You must have read the performance factors:

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/performance-considerations

Personally, I am also having trouble with these problems. I used A) modifying certain queries' SQL instead. Moreover, I developed a warm-up technique. Additionally, precompiling queries is a choice that may be beneficial.

When the programme first launches, a separate thread handles the warm-up method. There, it sends a fairly straightforward query to the database, forcing the model's construction and "triggering" the first startup delay for all requests. A flag is set after that query has completed running (it takes a few seconds). Before beginning, every other action waits for the flag to be set. This is quite helpful, especially in multithreaded situations.

I learned that each thread has its own starting latency. This implies that running three threads that each construct a context and attempt to execute some linq will make the whole programme wait for five seconds if the delay is, let's say, two seconds.

Keep in mind that while building custom queries, one must return all field needed to generate the object;

    var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList(); //works
    var blogs = context.Blogs.SqlQuery("SELECT [id] FROM dbo.Blogs").ToList(); //Does not.

Please take some time to test this subject since I have not thoroughly examined it. This is only a warning.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow