Created
November 15, 2013 22:37
-
-
Save mikecole/7492866 to your computer and use it in GitHub Desktop.
Context T4 template used by Reverse Engineer Code First - Before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ 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