I think there may be an issue with precompiling Complex Types in EF.

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Thu 08 May 2014 11:45

Hi,

I have this type of LINQ code which is using a complex type:

db.Class.OfType<I_Header>().Any(c => c.ReportId == myReportId)

Whatever I do, this line will only compile when first used. It seems impossible to precompile this EF Complex Type.

Thoughts?

Thanks,

Ed

EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Thu 08 May 2014 13:32

I have tried using a "Warmup" routine in the home controller with the following code:

db.Class.OfType<I_Header>().Any(c => c.ReportId > 0);

With the idea of calling the Any method on the Complex type before the main application was used, and then when it goes reused again via:

if (db.Class.OfType<I_Header>().Any(c => c.ReportId == myReportId))

It would perform quickly. But no effect. Second question still takes 10secs with View generation, on first load, then 50 ms thereafter....

Baffled......

EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Thu 08 May 2014 13:47

The complex type is referenced multiple times in the Pregenerated View file, so should be OK. Is there an issue with .OfType ?

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by Shalex » Mon 12 May 2014 14:33

Usage of any ORM usually leads to performance losses. In case of Entity Framework, there are a number of ways for optimization: http://msdn.microsoft.com/en-us/library/cc853327.aspx.
in the email you wrote:Fundementally I have a bit of code:

Code: Select all

if (db.Class.OfType().Any(c => c.ReportId == myReportId))
When I first hit it, it take 10 secs, when I hit it a second time it takes 50ms. Is this something that the "View Generation" should be able to sort?
Does your application talk to the database on startup? If not, you can implement a trick: run this first time-consuming query in a background thread on application startup so that all subsequent user requests would execute fast.

EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Mon 12 May 2014 14:45

Hi there,

Thanks for the reply.

my current solution is running all the code in global.asax as such:

Code: Select all

        void Session_OnStart()
        {
            // Session start-up code goes here.
            Warmup();
        }
        public Boolean Warmup()
        {
            System.Web.HttpContext.Current.Session["RID"] = 0; // 1013; // used in I .. Temp solution
            System.Web.HttpContext.Current.Session["SID"] = 0;// 1205; // used in I .. Temp solution
            I I = new I(); //Contains DB access code ie LINQ.Any queries etc which cause delays.

            return true;

Since I have about 12 entities like this, then the start time is lon.....g, and when I run it in Azure Websites on a shared instance, it blows my CPU quota away. So we have to use Basic or Standard dedicated instances.

However.... why should a simple derived class, using TPH, with one string property take 10 secs to have its query plan compiled? I am using EF5, .NET4.5. Rest of details to question is on StackOverflow as not sure if it is an EF question or a Devart Entity Developer issue?

See:
http://stackoverflow.com/questions/2355 ... h-tph-inhe


Thanks.

EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Mon 12 May 2014 14:55

Just reread your comment. Background thread...??? How do I do this?

Is this: "async Task" in ASP.NET MVC that came out in .NET 4.5? I am using MVC3 over .NET4.5

Anyway, why does TPH derived classes take so long to have have their query plans compile?

Thanks,

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by Shalex » Tue 13 May 2014 10:18

EdB wrote:Just reread your comment. Background thread...??? How do I do this?
Refer to http://stackoverflow.com/questions/1550 ... in-c-sharp.
EdB wrote:Anyway, why does TPH derived classes take so long to have have their query plans compile?
Sorry, but this question exceeds the goals of our support. Try to localize the issue; if it is caused by incorrect code generated by Entity Developer, please give us details, and we will investigate the question.

EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Tue 13 May 2014 10:41

Hi,
Sorry, but this question exceeds the goals of our support. Try to localize the issue; if it is caused by incorrect code generated by Entity Developer, please give us details, and we will investigate the question.
Understand the sentiment. However there are 3 potential causes:

a) Code that is generated by ED, using POCO template generator, and EDML, is causing the issue.

b) EF5 is not dealing with TPH as efficiently as one would like. This seems not the case as @Slauma on Stackoverflow did some test for me using non Devart TPH code using CodeFirst, and got ms responses. Also it is noted that only TPT has potential problems.

c) There is a problem with my Model. So I plan to create another simple base class and derived class off this to see if this is much quicker.

In answer to a), I would like to ask whether your generated TPH code produces identical performance to that produced by Microsoft tools. I would expect so, but would appreciate a confirmation, to negate ED as a cause.

Many thanks,

Edward

EdB
Posts: 91
Joined: Mon 15 Oct 2012 09:24

Re: I think there may be an issue with precompiling Complex Types in EF.

Post by EdB » Wed 14 May 2014 01:03

Hi,

I have been experimenting with the very excellent StackOverflow MiniProfiler. Results from this tool suggest that the issue lie with a particular Base Class in my model, since testing with more simple base classes and a derived class produces muck quicker results ie <100ms.

Thanks,

Edward

Post Reply