Search code examples
asp.netsql-servercode-firstpocoreverse

EntityFramework Reverse POCO Code First Generate Separate Folders


EntityFramework Reverse POCO Code First Generator do the code generation like this default generated classes Can we create a separate folder for repository, interfaces, configurations and POCO entities by changing tt file. at the moment all the classes generate on root of the application. can we create classes with folders like this. expected way to generate


Solution

  • Use these namespaces to specify where the different elements now live. These may even be in different assemblies. Please note this does not create the files in these locations, it only adds a using statement to say where they are.

    If you have a subscription, I show how this works on the plural sight course

    The way to do this is to add the "EntityFramework Reverse POCO Code First Generator" into each of these folders. Then set the .tt to only generate the relevant section you need by setting

     ElementsToGenerate = Elements.Poco; in your Entity folder,
     ElementsToGenerate = Elements.Context | Elements.UnitOfWork; in your Context folder,
     ElementsToGenerate = Elements.PocoConfiguration; in your Maps folder.
     PocoNamespace = "YourProject.Entities";
     ContextNamespace = "YourProject.Context";
     UnitOfWorkNamespace = "YourProject.Context";   
     PocoConfigurationNamespace = "YourProject.Maps";