none
Refreshing the EntityFramework designer RRS feed

  • Question

  • I find that a lot of the classes generated by EF (using the "Add Code Generation Item") EF 5.x DbContext Generator are great.

    However, if you need to update any of these classes (by placing a foreignkey column or to flatten data from other classes), they are rendered useless.

    You need to create ViewModel classes and place the code in there. If your model gets refreshed, I have to manually update my ViewModel classes that I created. You would also obviously lose your properties that you put in the generated class.

    If there is a better way of reusing the generated classes from EF in the above type of scenario, I would love to hear about it....


    Bill Yeager

    Friday, February 22, 2013 9:30 PM

Answers

  • Hi Bill,

    The way to do this is to use partial classes to split the custom logic from the generated code. http://msdn.microsoft.com/en-us/library/wa80x488(v=VS.80).aspx

    I'm not sure if the template adds the partial keyword to its classes, but they normally do. If not it shouldn't be too hard to modify the T4 template to add that in.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Thursday, February 28, 2013 5:54 PM
    Moderator

All replies

  • Hi,

    I am not sure if you are using WPF application. How did you modify the entities? Do you use the Model First Approach?

    Monday, February 25, 2013 7:42 AM
  • Hi Bill,

    The way to do this is to use partial classes to split the custom logic from the generated code. http://msdn.microsoft.com/en-us/library/wa80x488(v=VS.80).aspx

    I'm not sure if the template adds the partial keyword to its classes, but they normally do. If not it shouldn't be too hard to modify the T4 template to add that in.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Thursday, February 28, 2013 5:54 PM
    Moderator