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

Poco interfaces #789

Open sjh37 opened 1 year ago

sjh37 commented 1 year ago

Add an option to create a poco interface.

The {{moustache}} template will be something like this:

{{ClassModifier}} interface I{{NameHumanCaseWithSuffix}}{{#newline}}
{{{#newline}}

{{#each Columns}}
    {{#if OverrideModifier}}override {{/if}}{{WrapIfNullable}} {{NameHumanCase}} { get; {{PrivateSetterForComputedColumns}}set; }{{#newline}}
{{/each}}

{{#if HasReverseNavigation}}
{{#newline}}
{{#each ReverseNavigationProperty}}
    {{Definition}}{{#newline}}
{{/each}}
{{/if}}

{{#if HasForeignKey}}
{{#newline}}
{{#each ForeignKeys}}
    {{Definition}}{{#newline}}
{{/each}}
{{/if}}

{{#if EntityClassesArePartial}}
{{#newline}}
    void InitializePartial();{{#newline}}
{{/if}}
}{{#newline}}
revbones-dev commented 1 year ago

Once this is complete and the flag is set will it allow generation into separate files?

sjh37 commented 1 year ago

Hi @revbones-duplicate Yes it will

stevensrf11 commented 10 months ago

Does EF version 3.8.4 tt script have the ability to have each poco entity class create be able to be derived from a custom interface?

sjh37 commented 10 months ago

Does EF version 3.8.4 tt script have the ability to have each poco entity class create be able to be derived from a custom interface?

@stevensrf11 Yes it does. Here is an example of adding different base classes depending on name

// Use the following function if you need to apply additional modifications to a table
// Called just before UpdateColumn
Settings.UpdateTable = delegate(Table table)
{
    // To add a base class to a table based on column names. Also see Settings.UpdateColumn below.
    var tracking  = new List<string> { "createdby", "createdon", "modifiedby", "modifiedon" };
    var replicate = new List<string> { "uniqueid", "hrid"};
    if (table.Columns.Any(x => tracking.Contains(x.NameHumanCase)))
        table.BaseClasses = " : TrackingEntity";
    if (table.Columns.Any(x => replicate.Contains(x.NameHumanCase)))
        table.BaseClasses = " : ReplicateEntity";

    // To add attributes
    table.Attributes.Add("[Serializable]");
};
stevensrf11 commented 10 months ago

That example made no sense to me.

I want each poco entity class to derive IDLEntity.

 

How would I modify the tt script to do this

Sent: Friday, November 10, 2023 at 10:20 AM From: "Simon Hughes" @.> To: "sjh37/EntityFramework-Reverse-POCO-Code-First-Generator" @.> Cc: "stevensrf11" @.>, "Mention" @.> Subject: Re: [sjh37/EntityFramework-Reverse-POCO-Code-First-Generator] Poco interfaces (Issue #789)

 

Does EF version 3.8.4 tt script have the ability to have each poco entity class create be able to be derived from a custom interface?

@stevensrf11 Yes it does. Here is an example of adding different base classes depending on name

// Use the following function if you need to apply additional modifications to a table // Called just before UpdateColumn Settings.UpdateTable = delegate(Table table) { // To add a base class to a table based on column names. Also see Settings.UpdateColumn below. var tracking = new List { "createdby", "createdon", "modifiedby", "modifiedon" }; var replicate = new List { "uniqueid", "hrid"}; if (table.Columns.Any(x => tracking.Contains(x.NameHumanCase))) table.BaseClasses = " : TrackingEntity"; if (table.Columns.Any(x => replicate.Contains(x.NameHumanCase))) table.BaseClasses = " : ReplicateEntity";

// To add attributes
table.Attributes.Add("[Serializable]");

};

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

stevensrf11 commented 10 months ago

I understand this from a former post

Func<Table, string> WritePocoBaseClasses = t => { if (t.NameHumanCase== "Contact" || t.NameHumanCase== "Customer") { var r = new BaseClassMaker("BaseClass"); return r.ToString(); } }

 

But I have no clue what any of that code you shown below does.

 

 

What does this do and why would I want a new list?

Does creating these new variable mess up anything or change anying that works already?

why the use of the hard coded string what do the hard code string mean?

var tracking = new List { "createdby", "createdon", "modifiedby", "modifiedon" }; var replicate = new List { "uniqueid", "hrid"}; var replicate = new List { "uniqueid", "hrid"};

 

Is this suppose to create two base classes based for a table that  is named  by one if the string is  tracking and replicate variables?

 

if (table.Columns.Any(x => tracking.Contains(x.NameHumanCase))) table.BaseClasses = " : TrackingEntity";

if (table.Columns.Any(x => replicate.Contains(x.NameHumanCase))) table.BaseClasses = " : ReplicateEntity";

Sent: Friday, November 10, 2023 at 10:20 AM From: "Simon Hughes" @.> To: "sjh37/EntityFramework-Reverse-POCO-Code-First-Generator" @.> Cc: "stevensrf11" @.>, "Mention" @.> Subject: Re: [sjh37/EntityFramework-Reverse-POCO-Code-First-Generator] Poco interfaces (Issue #789)

 

Does EF version 3.8.4 tt script have the ability to have each poco entity class create be able to be derived from a custom interface?

@stevensrf11 Yes it does. Here is an example of adding different base classes depending on name

// Use the following function if you need to apply additional modifications to a table // Called just before UpdateColumn Settings.UpdateTable = delegate(Table table) { // To add a base class to a table based on column names. Also see Settings.UpdateColumn below. var tracking = new List { "createdby", "createdon", "modifiedby", "modifiedon" }; var replicate = new List { "uniqueid", "hrid"}; if (table.Columns.Any(x => tracking.Contains(x.NameHumanCase))) table.BaseClasses = " : TrackingEntity"; if (table.Columns.Any(x => replicate.Contains(x.NameHumanCase))) table.BaseClasses = " : ReplicateEntity";

// To add attributes
table.Attributes.Add("[Serializable]");

};

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

stevensrf11 commented 10 months ago

Ok I got it.

I see all I have to do is set table.BaseClasses equal to a class that derives from the interface.

Thanks

Steven

   

Sent: Friday, November 10, 2023 at 10:20 AM From: "Simon Hughes" @.> To: "sjh37/EntityFramework-Reverse-POCO-Code-First-Generator" @.> Cc: "stevensrf11" @.>, "Mention" @.> Subject: Re: [sjh37/EntityFramework-Reverse-POCO-Code-First-Generator] Poco interfaces (Issue #789)

 

Does EF version 3.8.4 tt script have the ability to have each poco entity class create be able to be derived from a custom interface?

@stevensrf11 Yes it does. Here is an example of adding different base classes depending on name

// Use the following function if you need to apply additional modifications to a table // Called just before UpdateColumn Settings.UpdateTable = delegate(Table table) { // To add a base class to a table based on column names. Also see Settings.UpdateColumn below. var tracking = new List { "createdby", "createdon", "modifiedby", "modifiedon" }; var replicate = new List { "uniqueid", "hrid"}; if (table.Columns.Any(x => tracking.Contains(x.NameHumanCase))) table.BaseClasses = " : TrackingEntity"; if (table.Columns.Any(x => replicate.Contains(x.NameHumanCase))) table.BaseClasses = " : ReplicateEntity";

// To add attributes
table.Attributes.Add("[Serializable]");

};

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

sjh37 commented 10 months ago

@stevensrf11

Settings.UpdateTable = delegate(Table table)
{
    table.BaseClasses = " : IDLEntity";
};
stevensrf11 commented 10 months ago

Thank you

Sent: Friday, November 10, 2023 at 7:31 PM From: "Simon Hughes" @.> To: sjh37/EntityFramework-Reverse-POCO-Code-First-Generator @.> Cc: stevensrf11 @.>, Mention @.> Subject: Re: [sjh37/EntityFramework-Reverse-POCO-Code-First-Generator] Poco interfaces (Issue #789)

@stevensrf11

Settings.UpdateTable = delegate(Table table)
{
    table.BaseClasses = " : IDLEntity";
};

-- Reply to this email directly or view it on GitHub: https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/issues/789#issuecomment-1806226016 You are receiving this because you were mentioned.

Message ID: @.***>