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

PocoNamespace Setting Not Working

Open issafram opened this issue 8 years ago • 4 comments

I thought that the following settings would apply custom namespaces to the different type of files.

Settings.PocoNamespace = "Test.TestPoco";
Settings.ContextNamespace = "Test.TestContext";
Settings.UnitOfWorkNamespace = "Test.TestUnitOfWork";
Settings.PocoConfigurationNamespace = "Test.TestPocoConfiguration";

But it just isn't working for me. Every single file is using the Settings.Namespace value.

What am I missing or doing incorrectly?

issafram avatar Jul 16 '18 17:07 issafram

Ok, I have just checked, and this looks to have been broken by a contribution. I shall mark this as a bug. Thanks for reporting it.

sjh37 avatar Jul 16 '18 20:07 sjh37

Just re-tested when I'm not tired. It is working after all. If you set

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

Then they are not used, that is because the generator is creating it all in the same namespace, and therefore does not require the different element namespaces.

The separate namespaces kick into action when you don't set it to generate everything, meaning you are going to generate some code in a different place.

So, create separate folders and/projects for your different things, like a folder for TestPoco into which you will put the poco classes. Copy the settings-file.tt into the TestPocofolder, set Settings.ElementsToGenerate = Elements.Poco; only, set Settings.ContextNamespace namespaces, etc as you have it above. and you will see that it is created ok. Copy the settings-file.tt into the TestContext folder, and set Settings.ElementsToGenerate = Elements.Context, save. and do the same for the other settings-file.tt in your other namespace folders.

If you move the settings-file.tt from your root into a sub folder, modify the top line to be:

<#@ include file="..\\EF.Reverse.POCO.Core.ttinclude" #>

and the line near the very bottom line to be

<#@ include file="..\\EF.Reverse.POCO.ttinclude" #>

sjh37 avatar Jul 17 '18 08:07 sjh37

I show you how to do this in a video at https://app.pluralsight.com/player?course=code-first-entity-framework-legacy-databases&author=simon-hughes&name=code-first-entity-framework-legacy-databases-m4&clip=0&mode=live

sjh37 avatar Jul 17 '18 08:07 sjh37

Interesting.... would you mind if I were to submit a PR at some point in the near future which allows for only one settings file? Doesn't necessarily need to create separate folders, just use the configured namespaces.

A user could then use ReSharper to automatically move all files to mapped namespace folders. Or a manual move.

issafram avatar Jul 17 '18 13:07 issafram