none
EF From Database Model Designer CS is empty, cannot change code generation strategy RRS feed

  • Question

  • I have been following some tutorials which create an entity data model and code in the model designer cs under model.edmx.

    This code uses namespace context and entities and I want to continue using this method.

    After generating the EDM the model designer cs is empty, but includes comment suggesting enabling legacy code generation.  This it says can be done by changing the 'Code Generation Strategy' designer property but this property is always greyed/disabled in the property window and if you change it in the xml it is not displayed at all in the property window and further model updates still do not add any code to model designer cs.

    Can any one help me to generate this code so that I can continue to use the same coding startegies i am already using?

    Thank you

    • Moved by Amanda Zhu Wednesday, January 7, 2015 5:59 AM
    Tuesday, January 6, 2015 1:40 PM

Answers

  • Hello hardy,

    >>I think I have finally solved this myself.

    It is glad to hear that you have got a workaround for your original issue. And it is recommended to open a new thread for new questions.

    >>s it a stable action to simply delete these or are they referenced somewhere else that will become unstable?

    Yes, this is the suggested way to use the ObjectContext that we need to delete the two .tt files.

    >>But my more recent project I think is using EF5.  And When I changed this to default code generation the generated code had no errors.

    This is because the team has moved classes to another new namespace:

    System.Data.EntityException => System.Data.Entity.Core.EntityException
    
    System.Data.Objects.ObjectContext => System.Data.Entity.Core.Objects.ObjectContext
    
    System.Data.Objects.DataClasses.RelationshipManager => System.Data.Entity.Core.Objects.DataClasses.RelationshipManager
    

    If you upgrade EF4 to EF5, it should be ok, since their namespace do not be replaced, while for EF6, please follow this article:

    http://msdn.microsoft.com/en-us/data/upgradeef6.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by hardy999 Wednesday, January 7, 2015 4:06 PM
    Wednesday, January 7, 2015 8:55 AM
    Moderator

All replies

  • I think I have finally solved this myself.  It seems you have to change the Code generation Strategy in the xml itself to "Default" then it appears in the properties window as "Legacy ObjectContext".

    Code Generation it seems is always implicit, so simply changing and saving the xml resulted in generation.

    I created a new model deleting the tt files originally created by default, then immediately changing the code generation strategy.  

    However my earlier edmx and tt files still exist. Is it a stable action to simply delete these or are they referenced somewhere else that will become unstable?

    Also I had an earlier solution which I think used EF6.  When I changed this to default code generation the generated code had errors since it could not find:

    using System.Data.EntityClient;
    using System.Data.Objects;
    using System.Data.Objects.DataClasses;

    But my more recent project I think is using EF5.  And When I changed this to default code generation the generated code had no errors.

    Would this have to do with the codegeneration EF version I had used?  How can I verify that this is the cause?  Can I see somewhere which codegeneration EF version is actually in use.  When you right click on the edm diagram and add one nothing changes anywhere that you can see.

    Tuesday, January 6, 2015 3:09 PM
  • Hi,

                     

    ADO.NET Entity Framework and LINQ to Entities forum is a better forum for your issue. I moved this thread there. You will get better support there.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 7, 2015 6:00 AM
  • Hello hardy,

    >>I think I have finally solved this myself.

    It is glad to hear that you have got a workaround for your original issue. And it is recommended to open a new thread for new questions.

    >>s it a stable action to simply delete these or are they referenced somewhere else that will become unstable?

    Yes, this is the suggested way to use the ObjectContext that we need to delete the two .tt files.

    >>But my more recent project I think is using EF5.  And When I changed this to default code generation the generated code had no errors.

    This is because the team has moved classes to another new namespace:

    System.Data.EntityException => System.Data.Entity.Core.EntityException
    
    System.Data.Objects.ObjectContext => System.Data.Entity.Core.Objects.ObjectContext
    
    System.Data.Objects.DataClasses.RelationshipManager => System.Data.Entity.Core.Objects.DataClasses.RelationshipManager
    

    If you upgrade EF4 to EF5, it should be ok, since their namespace do not be replaced, while for EF6, please follow this article:

    http://msdn.microsoft.com/en-us/data/upgradeef6.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by hardy999 Wednesday, January 7, 2015 4:06 PM
    Wednesday, January 7, 2015 8:55 AM
    Moderator
  • Thank you so much.  Appreciate it.
    Wednesday, January 7, 2015 4:05 PM