sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
706 stars 229 forks source link

How can I get the filenames and class names to be schema.TableName #686

Open nick5454 opened 3 years ago

nick5454 commented 3 years ago

lets say I have a table ( Ef6, .net framework 4.8 )

[foo].[Bar] where schema is "foo" and the table is "Bar"

How can I change the class files produced to be

filename: foo.Bar.cs

class declaration:

namespace Project.Defaultnamespace {
    namespace foo {
        public class Bar {
            ...

Any help would be greatly appreciated

sjh37 commented 3 years ago

It's not that straight forward, so would require some work.

A partial solution:

In your <database>.tt settings file set

Settings.PrependSchemaName = false;

Search for and change

public CodeOutput GeneratePoco(Table table)
{
    var filename = table.NameHumanCaseWithSuffix() + Settings.FileExtension;

to

public CodeOutput GeneratePoco(Table table)
{
    var filename = table.Schema.NameHumanCase + "." + table.NameHumanCaseWithSuffix() + Settings.FileExtension;

This names the files correctly, although you may want to do something with "dbo" schema.

Next would be to sort out the namespace, which requires more work on my part. I would start with adding a namespace field to the Table class, and work from there. I'll have to leave this as a todo item as it requires some time to resolve.