EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Add Settings.EnumNamespace

Open matt-neubert opened this issue 3 years ago • 1 comments

Blazor webassembly projects creates a Client, Server and Shared projects. Typically you wouldn't share the EF poco objects, but you may want to reuse the enums. Therefore, you may want to place them in the Shared project. It would be good give specific namespace for the enums when NOT generating them in the server t4 transform. While you can add the the project namespace in Settings.AdditionalNamespaces, it seems to be more logical to place them with the other namespace configuration sections. This then would be added to the appropriate files when there is an enum type replacement.

Settings.PocoNamespace              = ""; // "YourProject.Entities";
Settings.ContextNamespace           = ""; // "YourProject.Context";
Settings.InterfaceNamespace         = ""; // "YourProject.Interfaces";
Settings.PocoConfigurationNamespace = ""; // "YourProject.Configuration";
Settings.EnumNamespace = ""; // "YourProject.Configuration";

matt-neubert avatar Jan 20 '22 19:01 matt-neubert

Hi @matt-neubert

To do this, simply add the generator again to the Shared project, and copy your <database>.tt settings from your current file.

Shared project

In the shared project edit the following line to just the elements you want

Settings.ElementsToGenerate = Elements.Enum;

// You have to now reference the main project, so you need to add in its namespace.
Settings.PocoNamespace              = "YourProject.Main"; // "YourProject.Entities";
Settings.ContextNamespace           = "YourProject.Main"; // "YourProject.Context";
Settings.InterfaceNamespace         = "YourProject.Main"; // "YourProject.Interfaces";
Settings.PocoConfigurationNamespace = "YourProject.Main"; // "YourProject.Configuration";

Main project

And in your main project, remove enum element as this is generated in another project:

Settings.ElementsToGenerate = Elements.Poco | Elements.Context | Elements.Interface | Elements.PocoConfiguration;

// You have to now reference the other enum project, so you need to add in the namespace where it is used
Settings.EnumNamespace = "YourProject.Shared"; // The namespace is of your shared project where the Enums reside.

I show this in a video over at PluralSight if you have a subscription: https://www.pluralsight.com/courses/code-first-entity-framework-legacy-databases. The module is this one https://app.pluralsight.com/course-player?clipId=7ca1ff82-fbb5-40f3-8c26-cc4e0752751f

sjh37 avatar Jan 21 '22 14:01 sjh37