0

I have a custom entity data model extension that implements IModelGenerationExtension. Without getting into specific code, I have come across a situation where I get the "A model generation extension made changes to the model generated from the database that were not valid." when updating my model from the database. I am able to completely step through my extension using the Visual Studio experimental instance. The xml document representing the EDMX file modified by extension is valid xml. The error occurs after the scope leaves my OnAfterModelGenerated method. I'm assuming I did something the EF entity data model wizard doesn't like. How can I determine what the actual error is? I find that info for this sort of thing is not readily available. Any help would be appreciated. Thanks in advance.

SteveB
  • 233
  • 3
  • 12

2 Answers2

0

You can save the resulting .edmx as a new file and open it in Visual Studio. It will show the errors it has.

Ivan Ferrer Villa
  • 2,129
  • 1
  • 26
  • 23
  • I had realized my problem was that I was trying to bite off more than I could chew. I was attempting to rename entities since it doesn't pluralize an entity that ends with an "s". I must've gotten something wrong. I started researching adding trace statements to debug what my code was doing while it was happening but got sidetracked onto something else. I will have to try your suggestion and get back to you. – SteveB Sep 25 '15 at 03:48
  • You should know that you can add breakpoints in code view's left margin and debug `.tt` files by right-clicking the file in solution explorer ->Debug T4 Template. I'm trying to rename entities too, and had to make my own class implementing `IModelTransformExtension`. Entities should also be renamed in `.edmx.diagram` files. A real pain! I cannot understand how nowadays there is not a place in EF where we can inject our custom method to process entity/property names in db-first model. Good luck! – Ivan Ferrer Villa Sep 25 '15 at 09:26
  • My problem was that when I was changing names of entities, the edmx wasn't saved yet. There was some issue with not being able to save it since it no longer matched the diagram. Yeah, there was no easy way around it so I just throw up a message box for the user to rename it manually. I'm still on the same version but I don't think this got any easier. – SteveB May 19 '17 at 20:38
0

Use OnAfterModelGenerated to edit the CurrentDocument only when WizardKind==WizardKind.Generate.

Tim
  • 140
  • 1
  • 1
  • 5