none
Entity Framework View Generation RRS feed

  • Question

  • Hello,

    We are using Entity Framework Code First. I am trying to use the view generation feature of the EF power tools to speed up the start times of the app. The tool successfully completes and generates a *.views.cs file. However the generated class does not get used - the constructor does not get called. I tried doing this on a simple test program and it works as expected. The difference between the test program and our system is that the POCO model classes are located in a completely different assembly/namespace to the Entitiy Framework context class. Is it possible on start up to explicitly specify the class containgin the view generation code? Any advice would be appreciated.

    Thanks,

    Harsha

    Friday, April 13, 2012 12:05 PM

Answers

  • Hi HarshaP,

    I recently had to troubleshoot a similar situation. It turns out that the views file needed to be located in the assembly with the POCO classes rather than the context. As to why this is the case I can't say. I'd dare say this is a bug, or if it was by design I disagree with that design decision, since you're storing information about the data-store in an assembly which in our case is being shared between client and server and used as DataContracts for WCF.

    In response to the question regarding being able to explicitly specify the class containing the view information, no this unfortunately isn't possible.

    Regards,

    Tyler

    • Marked as answer by HarshaP Monday, April 16, 2012 1:41 PM
    Saturday, April 14, 2012 1:15 PM

All replies

  • Hi HarshaP,

    I recently had to troubleshoot a similar situation. It turns out that the views file needed to be located in the assembly with the POCO classes rather than the context. As to why this is the case I can't say. I'd dare say this is a bug, or if it was by design I disagree with that design decision, since you're storing information about the data-store in an assembly which in our case is being shared between client and server and used as DataContracts for WCF.

    In response to the question regarding being able to explicitly specify the class containing the view information, no this unfortunately isn't possible.

    Regards,

    Tyler

    • Marked as answer by HarshaP Monday, April 16, 2012 1:41 PM
    Saturday, April 14, 2012 1:15 PM
  • Hello Tyler,

    Thanks for your reply. I have tried moving the generated view class into the assembly containing the POCO domain classes and it is getting created. This is definitely a bug. It should look for such a class in the same assembly as the context class. However it has not made improvement to the application load performance. It takes 31 seconds to retrieve the first object from the database! I will have a look at the other recommendations for improving EF performance.

    Thanks,

    Harsha

    Monday, April 16, 2012 1:41 PM
  • Hi, i found a solution for this, instead of moving the generated views outside the ObjectContext's project, leave it in the ObjectContext's project and as soon as you create the context try do:

    context.MetadataWorkspace.LoadFromAssemby(typeof(MyContext).Assembly) ;

    Hope it helps!


    Thursday, May 24, 2012 11:02 AM