This is a migrated thread and some comments may be shown as answers.

Context creation time is too long

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kemal
Top achievements
Rank 1
Kemal asked on 04 Dec 2015, 12:41 AM

Hi,

My context have more than 600 entity (table & view).

Context creation time is approximately 8sn.

It's too long for request based context creation model.

How can i reduce creation time?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 08 Dec 2015, 12:01 PM
Hi Kemal,

long time for creating a context instance is an indication that you do something extra. Typical reason for such timing could be code like this:

public partial class TestPolimorphicRefsContext : OpenAccessContext
    {
        static MetadataSource metadataSource = new TestPolimorphicRefsMetadataSource();
        static BackendConfiguration backendConfiguration = new BackendConfiguration()
        {
            Backend = "mssql"
        };
 
        public TestPolimorphicRefsContext()
            : base(DbConnection, backendConfiguration, metadataSource)
        {
 
        }
}

The above code creates once a MetadataSource instance and passes it each time to the constructor when it gets invoked. In this case the constructor calls a method which prepares the metadata each time, if you have lots of entities in the metadata this could be costly operation. If you have this patter in your code I would suggest you to change to the following:
public partial class TestPolimorphicRefsContext : OpenAccessContext
    {
        static MetadataContainer metadataContainer = new TestPolimorphicRefsMetadataSource().GetModel();
        static BackendConfiguration backendConfiguration = new BackendConfiguration()
        {
            Backend = "mssql"
        };
 
        public TestPolimorphicRefsContext()
            : base(DbConnection, backendConfiguration, metadataContainer)
        {
 
        }
}

Here as you can see the complete metadataContainer is prepared upfront once and then it is re-used in each and every context created after that. The first creation would still be slightly longer, might be comparable with the timing you mention but all next creations should be almost immediate.

PS: have in mind that if you apply some logic and modify the metadata inside the FluentMetadataSource the approach above will not work as the resulted metadataContainer will be cached the first time. 

Hope this helps. 

Regards,
Kaloyan Nikolov
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
General Discussions
Asked by
Kemal
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or