locked
Context T4 Creating a Duplicate Context Class called Context1.cs RRS feed

  • Question

  • We have an Entity Framework 4 project using T4 templates to generate the Entities and the context from the model. We have modified them slightly to separate the entities from the context and to make the context implement an IContext interface for unit testing purposes.

    This has been working fine for a few weeks but recently when the model is modified e.g. adding a table and the T4's re-run, an extra context class is generated alongside the existing one. The existing one is correctly updated but the second one is also created with a file name of PharmacyNHSClaims.Context1.cs (the correct context is called PharmacyNHSClaims.Context.cs). As it is an identical class it causes many compile errors. The problem is fixed by deleting the extra context (Context1.cs)

    We have checked back through the source control history and cannot find an changes to the model or the T4 that would cause this. We have searched the internet for any mention of this issue but without luck.

    Has anyone encountered this issue or can suggest what might be causing it?

    Thanks

    Stephen


    Stephen

    Monday, November 25, 2013 12:00 PM

Answers

  • Hi,

    As it is an autogenerated class, it could be that Context.cs file exists in your project and then, at any time, when yours classes were genetared again, a Context1.cs file was added instead of Context.cs one.

    To turn on again to Context.cs file, you should edit your .proj file manually outside VS. Search then in the .proj file for Context1.cs and change back to Context.cs.

    Save the file an reload the project again in VS. Your files should generate correctly now.

    Regards.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.



    • Marked as answer by -Ozymandias- Monday, November 25, 2013 3:31 PM
    • Edited by JA Reyes Monday, November 25, 2013 3:34 PM
    Monday, November 25, 2013 12:13 PM

All replies

  • Hi,

    As it is an autogenerated class, it could be that Context.cs file exists in your project and then, at any time, when yours classes were genetared again, a Context1.cs file was added instead of Context.cs one.

    To turn on again to Context.cs file, you should edit your .proj file manually outside VS. Search then in the .proj file for Context1.cs and change back to Context.cs.

    Save the file an reload the project again in VS. Your files should generate correctly now.

    Regards.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.



    • Marked as answer by -Ozymandias- Monday, November 25, 2013 3:31 PM
    • Edited by JA Reyes Monday, November 25, 2013 3:34 PM
    Monday, November 25, 2013 12:13 PM
  • Thanks for posting this. Go me out of a edmx chasm…..
    Thursday, December 19, 2013 12:15 PM