Designer configure UseSqlOutputClause (EF)

Posts   
 
    
Posts: 2
Joined: 03-Oct-2025
# Posted on: 03-Oct-2025 09:08:03   

LLBLGen Pro version: 5.12 (5.12.1) RTM

.NET version: 8.0

Database: SQL Server 2017

Hi,

I'm currently customizing the ModelBuilder template to conditionally apply .UseSqlOutputClause(false) during inserts in EF Core, based on a custom property (UseSqlOutputClause) defined in OutputSettingValues.CustomProperties.

This helps us avoid issues with triggers and constraints in our database setup.

At the moment, I'm manually updating the generated ModelBuilder file in the LLBLGen application programs folder after each code generation run.

I'm not sure if LLBLGen already provides a built-in way to configure this behavior through the designer or metadata—if it does, I'd love to know how to use it.

If not, would it be possible to consider adding support for this in a future version, either as a per-entity setting or a global option?

Thanks in advance for your help!

Andreas

what i would like to achieve:

protected virtual void MapAddressEntity(EntityTypeBuilder<AddressEntity> config)
{
    config.ToTable("Address", tb => tb.UseSqlOutputClause(false));
}

how i currently fixed it: (modelbuilder.lpt)

        protected virtual void Map<%=entity.Name%>(EntityTypeBuilder<<%=entity.Name%>> config)
        {
            <% var useSqlOutput = false;
            if(entity.OutputSettingValues.CustomProperties.ContainsKey("UseSqlOutputClause"))
            {
                useSqlOutput = entity.OutputSettingValues.CustomProperties["UseSqlOutputClause"].ToString().ToLower() == "true";
            }
            %>config.ToTable("<%=mapping.MappedTarget.Name%>"<%
                if(mapping.MappedTarget.ContainingSchema.SchemaOwner!=defaultSchema) { %>, "<%=mapping.MappedTarget.ContainingSchema.SchemaOwner%>"<% } 
                if(supportsTemporalTables && targetIsTemporalTable) { %>, b=>b.IsTemporal(b=> { b.HasPeriodStart("<%=periodStartField.FieldName%>"); b.HasPeriodEnd("<%=periodEndField.FieldName%>");})<%}
                if(!string.IsNullOrEmpty(tptDifferentPkTargetNames)) { %>, <%=tptDifferentPkTargetNames%><% } 
                if(useSqlOutput) { %>, tb => tb.UseSqlOutputClause(false)<% } 
                %>);

...
Posts: 2
Joined: 03-Oct-2025
# Posted on: 03-Oct-2025 10:19:53   

Hi,

To make this easier for my team and ensure consistency across environments, I’d like to move the updated ModelBuilder file to a relative folder in our repository

(making use of the Additional Templates Folder in project settings?)

(e.g. /llblgen-templates/ModelBuilder/) and configure LLBLGen to generate code using that version of the file instead of the default one.

Is there a supported way to override the default location of the ModelBuilder file or bind it to a custom path within the project settings?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39951
Joined: 17-Aug-2003
# Posted on: 05-Oct-2025 08:29:48   

This is possible, you can define a new templatebindings file with the binding for ModelBuilder.lpt, which is using the SD_EF_Core_ModelBuilder templateID, and bind it to a different file. Then when defining the code generation task (F7 -> double click the task), specify the templatebindings file with your binding above the existing one in the templatebindings tab that's visualized when you click 'Advanced' button.

More info about templatebindings: https://www.llblgen.com/Documentation/5.12/Designer/Functionality%20Reference/TemplateBindingsViewer.htm and https://www.llblgen.com/Documentation/5.12/SDK/templates_templatesystem.htm#templatebindings-files-xml-format

This way you use an alternative version of the modelbuilder template during code generation, basically overriding the existing one shipped with the designer.

An alternative could be to generate derived class for the model builder using a new template (which thus requires a new .lpt file and template bindings file and a new task added to the preset you're using, see e.g. https://www.llblgen.com/Documentation/5.12/Designer/How%20To/TemplatesAdd.htm), and override the Map* methods for the entities which have fields with this setting, then first call the base method and then alter the properties which need this clause set. This might be a better solution as you don't have to keep track of existing templates if they might get updated (so you then have to migrate those changes to your copy e.g. the copy of the ModelBuilder.lpt with your own changes)

Frans Bouma | Lead developer LLBLGen Pro