Skip to content

Instantly share code, notes, and snippets.

@mikecole
Created November 15, 2013 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecole/7492866 to your computer and use it in GitHub Desktop.
Save mikecole/7492866 to your computer and use it in GitHub Desktop.
Context T4 template used by Reverse Engineer Code First - Before
<#@ template hostspecific="true" language="C#" #>
<#@ include file="EF.Utility.CS.ttinclude" #><#@
output extension=".cs" #><#
var efHost = (EfTextTemplateHost)Host;
var code = new CodeGenerationTools(this);
#>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using <#= code.EscapeNamespace(efHost.MappingNamespace) #>;
namespace <#= code.EscapeNamespace(efHost.Namespace) #>
{
public partial class <#= efHost.EntityContainer.Name #> : DbContext
{
static <#= efHost.EntityContainer.Name #>()
{
Database.SetInitializer<<#= efHost.EntityContainer.Name #>>(null);
}
public <#= efHost.EntityContainer.Name #>()
: base("Name=<#= efHost.EntityContainer.Name #>")
{
}
<#
foreach (var set in efHost.EntityContainer.BaseEntitySets.OfType<EntitySet>())
{
#>
public DbSet<<#= set.ElementType.Name #>> <#= set.Name #> { get; set; }
<#
}
#>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
<#
foreach (var set in efHost.EntityContainer.BaseEntitySets.OfType<EntitySet>())
{
#>
modelBuilder.Configurations.Add(new <#= set.ElementType.Name #>Map());
<#
}
#>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment