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

Poco interfaces

Open sjh37 opened this issue 2 years ago • 9 comments

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}}

sjh37 avatar Jan 23 '23 17:01 sjh37

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

revbones-dev avatar Jan 30 '23 16:01 revbones-dev

Hi @revbones-duplicate Yes it will

sjh37 avatar Jan 30 '23 21:01 sjh37

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 avatar Nov 10 '23 14:11 stevensrf11

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]");
};

sjh37 avatar Nov 10 '23 15:11 sjh37

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 avatar Nov 10 '23 15:11 stevensrf11

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 avatar Nov 10 '23 15:11 stevensrf11

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: @.***>

stevensrf11 avatar Nov 10 '23 15:11 stevensrf11

@stevensrf11

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

sjh37 avatar Nov 10 '23 18:11 sjh37

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: @.***>

stevensrf11 avatar Nov 10 '23 19:11 stevensrf11