mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-08 02:14:44 +08:00
调整T4模板,领域模型增加注释
This commit is contained in:
@@ -1,73 +1,130 @@
|
||||
<#@ 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;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenAuth.Domain
|
||||
{
|
||||
public partial class <#= efHost.EntityType.Name #>
|
||||
{
|
||||
<#
|
||||
var collectionNavigations = efHost.EntityType.NavigationProperties.Where(
|
||||
np => np.DeclaringType == efHost.EntityType
|
||||
&& np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||
|
||||
// Add a ctor to initialize any collections
|
||||
if (collectionNavigations.Any())
|
||||
{
|
||||
#>
|
||||
public <#= code.Escape(efHost.EntityType) #>()
|
||||
{
|
||||
<#
|
||||
foreach (var navProperty in collectionNavigations)
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(navProperty) #> = new List<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>>();
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
#>
|
||||
<#= Accessibility.ForProperty(property) #> <#= typeUsage #> <#= code.Escape(property) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var navProperty in efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType))
|
||||
{
|
||||
if (navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
|
||||
{
|
||||
#>
|
||||
public virtual ICollection<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
public virtual <#= code.Escape(navProperty.ToEndMember.GetEntityType()) #> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
}
|
||||
}
|
||||
<#@ template hostspecific="true" language="C#" #>
|
||||
<#@ include file="EF.Utility.CS.ttinclude" #><#@
|
||||
output extension=".cs" #><#
|
||||
|
||||
var efHost = (EfTextTemplateHost)Host;
|
||||
var code = new CodeGenerationTools(this);
|
||||
code.GetSummryDictionary(".",efHost.EntityContainer.Name,efHost.EntityType.Name,"sa","000000");
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// <#= code.GetSummry(code.Escape(efHost.EntityType.Properties[0])) #>
|
||||
/// </summary>
|
||||
public partial class <#= efHost.EntityType.Name #>
|
||||
{
|
||||
<#
|
||||
var collectionNavigations = efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many);
|
||||
|
||||
foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
#>
|
||||
/// <summary>
|
||||
/// <#= code.GetSummry(code.Escape(property)) #>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
<#= Accessibility.ForProperty(property) #> <#= typeUsage #> <#= code.Escape(property) #> { get; set; }
|
||||
|
||||
<#
|
||||
}
|
||||
|
||||
foreach (var navProperty in efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType))
|
||||
{
|
||||
if (navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
|
||||
{
|
||||
#>
|
||||
public virtual ICollection<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
public virtual <#= code.Escape(navProperty.ToEndMember.GetEntityType()) #> <#= code.Escape(navProperty) #> { get; set; }
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
|
||||
public <#= code.Escape(efHost.EntityType) #>()
|
||||
{
|
||||
<# foreach (var property in efHost.EntityType.Properties)
|
||||
{
|
||||
var typeUsage = code.Escape(property.TypeUsage);
|
||||
|
||||
// Fix-up spatial types for EF6
|
||||
if (efHost.EntityFrameworkVersion >= new Version(6, 0)
|
||||
&& typeUsage.StartsWith("System.Data.Spatial."))
|
||||
{
|
||||
typeUsage = typeUsage.Replace(
|
||||
"System.Data.Spatial.",
|
||||
"System.Data.Entity.Spatial.");
|
||||
}
|
||||
if(typeUsage=="System.Guid")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= Guid.NewGuid();
|
||||
<#}
|
||||
else if(typeUsage=="System.DateTime")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= DateTime.Now;
|
||||
<#}
|
||||
else if(typeUsage=="bool")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= false;
|
||||
<# }
|
||||
else if(typeUsage=="int"||typeUsage=="double")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= 0;
|
||||
<# }
|
||||
else if(typeUsage=="byte[]")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= new byte[0];
|
||||
<# }
|
||||
else if(typeUsage=="decimal")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= 0M;
|
||||
<# }
|
||||
else if(typeUsage=="string")
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(property) #>= string.Empty;
|
||||
<#}
|
||||
else{ }
|
||||
}
|
||||
if (collectionNavigations.Any())
|
||||
{
|
||||
foreach (var navProperty in collectionNavigations)
|
||||
{
|
||||
#>
|
||||
this.<#= code.Escape(navProperty) #> = new List<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>>();
|
||||
<#
|
||||
}
|
||||
|
||||
}#>
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Id);
|
||||
|
||||
// Table & Column Mappings
|
||||
this.ToTable("ModuleRole");
|
||||
this.Property(t => t.Id).HasColumnName("Id");
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Id);
|
||||
|
||||
// Table & Column Mappings
|
||||
this.ToTable("PageElementGrant");
|
||||
this.Property(t => t.Id).HasColumnName("Id");
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
// Primary Key
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.DomId)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
// Primary Key
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Theme)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
// Primary Key
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Email)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
// Primary Key
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Account)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
// Primary Key
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
// Properties
|
||||
// Table & Column Mappings
|
||||
this.ToTable("UserModule");
|
||||
this.Property(t => t.Id).HasColumnName("Id");
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Id);
|
||||
|
||||
// Table & Column Mappings
|
||||
this.ToTable("UserOrg");
|
||||
this.Property(t => t.Id).HasColumnName("Id");
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
this.HasKey(t => t.Id);
|
||||
|
||||
// Properties
|
||||
this.Property(t => t.Id);
|
||||
|
||||
// Table & Column Mappings
|
||||
this.ToTable("UserRole");
|
||||
this.Property(t => t.Id).HasColumnName("Id");
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user