In Entity Developer, you can use templates to manage the overwrite behavior of the application.
Changing the output parameters of a template, including management of the override behavior, is implemented using the PushOutputRedirection function call for the internal reserved variable of a template, that is called Output.
The function has many overloads and has the following signature in its full-scale form:
public void PushOutputRedirection(OutputInfo outputInfo,
string parentFileName,
string targetFileName,
OverwriteMode overwriteMode,
string buildAction,
CopyToOutputDirectory copyToOutputDirectory)
In custom templates you can use the following additional parameters with the PushOutputRedirection function that can be called inside the template code:
Typically, every time you save your project, all generated files are overwritten. However, such overwrite behavior might not always be convenient.
The OverwriteMode parameter can have the following values:
Additionally, using this technique you can create and store unchanged your sample files for re-use in subsequent iterations.
Below is the example of a template that illustrates how to manage the overwrite behavior.
<#
// Empty template for Devart Entity Developer C# code generation.
// Copyright (c) 2008-2026 Devart. All rights reserved.
#>
<#@ template language="C#" #>
<#@ import namespace="EntityDeveloper.TemplateEngine" #>
<#@ property name="InterfacesOutput" category="Output" type="OutputInfo" #>
<#@ property name="ClassesOutput" category="Output" type="OutputInfo" #>
<#@ extended name="GenerateRepository" type="System.Boolean" owner="Class" default="true" #>
<#
// Settings
output.Extension = ".cs";
foreach(Class cls in model.Classes) {
if (!(bool)cls.GetProperty("GenerateRepository"))
continue;
output.PushOutputRedirection(InterfacesOutput, "", "I" + cls.Name + "Repository", OverwriteMode.None);
#>
using System;
using System.Collections.Generic;
namespace DataContext {
public interface I<#= codeProvider.GetValidIdentifier(cls.FullName) #>Repository {
void Insert<#= codeProvider.GetValidIdentifier(cls.FullName) #>(<#= codeProvider.GetValidIdentifier(cls.FullName) #> item);
void Delete<#= codeProvider.GetValidIdentifier(cls.FullName) #>(<#= codeProvider.GetValidIdentifier(cls.FullName) #> item);
}
}
<#
output.PopOutputRedirection();
output.PushOutputRedirection(ClassesOutput, "", cls.Name + "Repository", OverwriteMode.Merge);
#>
using System.Linq;
using System.Collections.Generic;
namespace DataContext {
public class <#= codeProvider.GetValidIdentifier(cls.FullName) #>Repository : I<#= codeProvider.GetValidIdentifier(cls.FullName) #>Repository {
public <#= codeProvider.GetValidIdentifier(cls.FullName) #>Repository(IDatasource datasource) {
this.Datasource = datasource;
}
public void Insert<#= codeProvider.GetValidIdentifier(cls.FullName) #>(<#= codeProvider.GetValidIdentifier(cls.FullName) #> item) {
this.Datasource.Insert<#= codeProvider.GetValidIdentifier(cls.FullName) #>(item);
}
public void Delete<#= codeProvider.GetValidIdentifier(cls.FullName) #>(<#= codeProvider.GetValidIdentifier(cls.FullName) #> item) {
this.Datasource.Delete<#= codeProvider.GetValidIdentifier(cls.FullName) #>(item);
}
public IDatasource Datasource {
get;
private set;
}
}
}
<#
output.PopOutputRedirection();
}
#>