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
700 stars 230 forks source link

Error in generating tables #768

Open apotplant opened 1 year ago

apotplant commented 1 year ago

Hi there,

I just purchased a license to do this.

I would like the following tables to be generated but get this error when I run the POCO generator.

SAS_BETA_TRAN1 and SAS_BETA_TRANS both resolve to the same C# name. Filter one of them out.

This seems like a bug to me. Would appreciate some help in this

sjh37 commented 1 year ago

Hi @apotplant

This is not a bug. Quite the opposite, it detects where the two or more tables would resolve to the same C# name. For example the following 4 table names would all resolve to the same C# class name, two of them due to pluralisation and two due to CamelCasing:

Using the two table names you provided:

CREATE TABLE SAS_BETA_TRAN1 (id INT NOT NULL, CONSTRAINT pk_a PRIMARY KEY (id));
CREATE TABLE SAS_BETA_TRANS (id INT NOT NULL, CONSTRAINT pk_b PRIMARY KEY (id));

It generated both classes:

// SAS_BETA_TRANS
public class SasBetaTran
{
    public int Id { get; set; } // id (Primary key)
}

// SAS_BETA_TRAN1
public class SasBetaTran1
{
    public int Id { get; set; } // id (Primary key)
}

In your <database>.tt file, what have you got inside of the Settings.TableRename function?

Also, near the bottom of your <database>.tt file, what have you got the pluralisation set to?

Inflector.PluralisationService = new EnglishPluralizationService();

I suspect you have other tables that resolve to the same name and not those two. Try turning pluralisation off for now, see what is output

Inflector.PluralisationService = null;