T4Map
This commit is contained in:
parent
584bd0b185
commit
b030ef6ea1
File diff suppressed because it is too large
Load Diff
@ -1,386 +1,386 @@
|
|||||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||||
<#@ assembly name="System.Core" #>
|
<#@ assembly name="System.Core" #>
|
||||||
<#@ import namespace="System" #>
|
<#@ import namespace="System" #>
|
||||||
<#@ import namespace="System.Linq" #>
|
<#@ import namespace="System.Linq" #>
|
||||||
<#@ import namespace="System.Text" #>
|
<#@ import namespace="System.Text" #>
|
||||||
<#@ import namespace="System.IO" #>
|
<#@ import namespace="System.IO" #>
|
||||||
<#@ import namespace="System.Collections.Generic" #>
|
<#@ import namespace="System.Collections.Generic" #>
|
||||||
<#@ import namespace="System.Reflection" #>
|
<#@ import namespace="System.Reflection" #>
|
||||||
<#@ import namespace="System.ComponentModel" #>
|
<#@ import namespace="System.ComponentModel" #>
|
||||||
<#@ output extension=".cs" #>
|
<#@ output extension=".cs" #>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// T4模板类:基础Map类
|
// T4模板类:基础Map类
|
||||||
// 此代码由T4模板自动生成
|
// 此代码由T4模板自动生成
|
||||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
using APT.Infrastructure.EF.Map;
|
using APT.Infrastructure.EF.Map;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
namespace APT.MS.Data.Mapping
|
namespace APT.MS.Data.Mapping
|
||||||
{
|
{
|
||||||
<#
|
<#
|
||||||
List<string> dlls=new List<string>();
|
List<string> dlls=new List<string>();
|
||||||
List<string> filePaths=new List<string>();
|
List<string> filePaths=new List<string>();
|
||||||
List<TableT4> tables = new List<TableT4>();
|
List<TableT4> tables = new List<TableT4>();
|
||||||
List<string> modules=new List<string> ();
|
List<string> modules=new List<string> ();
|
||||||
|
|
||||||
dlls.Add(Host.ResolveAssemblyReference("$(SolutionDir)"+"APT.MS.Domain\\"));
|
dlls.Add(Host.ResolveAssemblyReference("$(SolutionDir)"+"APT.MS.Domain\\"));
|
||||||
dlls.Add(Host.ResolveAssemblyReference("$(SolutionDir)"+"APT.BaseData.Domain\\"));
|
dlls.Add(Host.ResolveAssemblyReference("$(SolutionDir)"+"APT.BaseData.Domain\\"));
|
||||||
|
|
||||||
foreach(var dll in dlls){
|
foreach(var dll in dlls){
|
||||||
GetFileName(filePaths,dll);
|
GetFileName(filePaths,dll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach(var p in filePaths)
|
foreach(var p in filePaths)
|
||||||
{
|
{
|
||||||
var classText = File.ReadAllText(p, Encoding.UTF8);
|
var classText = File.ReadAllText(p, Encoding.UTF8);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(classText))
|
if (!string.IsNullOrEmpty(classText))
|
||||||
{
|
{
|
||||||
int classTextIndex = 0;
|
int classTextIndex = 0;
|
||||||
var space = GetElement(classText, "namespace", "{", ref classTextIndex);
|
var space = GetElement(classText, "namespace", "{", ref classTextIndex);
|
||||||
if (!string.IsNullOrEmpty(space)&& space.IndexOf("Domain.Entities", StringComparison.OrdinalIgnoreCase) > -1)
|
if (!string.IsNullOrEmpty(space)&& space.IndexOf("Domain.Entities", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
var classEleTxt = GetElement(classText, string.Empty, ":", ref classTextIndex);
|
var classEleTxt = GetElement(classText, string.Empty, ":", ref classTextIndex);
|
||||||
classTextIndex--;
|
classTextIndex--;
|
||||||
var baseClassTxt=GetElement(classText, ":", "{", ref classTextIndex);
|
var baseClassTxt=GetElement(classText, ":", "{", ref classTextIndex);
|
||||||
if (!string.IsNullOrEmpty(classEleTxt))
|
if (!string.IsNullOrEmpty(classEleTxt))
|
||||||
{
|
{
|
||||||
TableT4 tableT4 = new TableT4();
|
TableT4 tableT4 = new TableT4();
|
||||||
tableT4.TableNameSpace = space;
|
tableT4.TableNameSpace = space;
|
||||||
tableT4.BaseName = baseClassTxt;
|
tableT4.BaseName = baseClassTxt;
|
||||||
tableT4.BaseEntityName="APTEntityBaseMap";
|
tableT4.BaseEntityName="APTEntityBaseMap";
|
||||||
if(tableT4.BaseName.IndexOf("TreeEntityBase<")>-1){
|
if(tableT4.BaseName.IndexOf("TreeEntityBase<")>-1){
|
||||||
tableT4.BaseEntityName="TreeEntityBaseMap";
|
tableT4.BaseEntityName="TreeEntityBaseMap";
|
||||||
}
|
}
|
||||||
tables.Add(tableT4);
|
tables.Add(tableT4);
|
||||||
int classEleTxtIndex = 0;
|
int classEleTxtIndex = 0;
|
||||||
var attrTxt= GetElement(classEleTxt, "[", "]", ref classEleTxtIndex);
|
var attrTxt= GetElement(classEleTxt, "[", "]", ref classEleTxtIndex);
|
||||||
while (!string.IsNullOrEmpty(attrTxt))
|
while (!string.IsNullOrEmpty(attrTxt))
|
||||||
{
|
{
|
||||||
if(attrTxt=="IgnoreT4")
|
if(attrTxt=="IgnoreT4")
|
||||||
{
|
{
|
||||||
tableT4.IgnoreT4=true;
|
tableT4.IgnoreT4=true;
|
||||||
}
|
}
|
||||||
tableT4.Attrs.Add(attrTxt);
|
tableT4.Attrs.Add(attrTxt);
|
||||||
attrTxt = GetElement(classEleTxt, "[", "]", ref classEleTxtIndex);
|
attrTxt = GetElement(classEleTxt, "[", "]", ref classEleTxtIndex);
|
||||||
}
|
}
|
||||||
if(tableT4.IgnoreT4)
|
if(tableT4.IgnoreT4)
|
||||||
continue;
|
continue;
|
||||||
var classEleTxt1 = GetElement(classEleTxt, "class", "", ref classEleTxtIndex);
|
var classEleTxt1 = GetElement(classEleTxt, "class", "", ref classEleTxtIndex);
|
||||||
if (!string.IsNullOrEmpty(classEleTxt1))
|
if (!string.IsNullOrEmpty(classEleTxt1))
|
||||||
tableT4.Name = classEleTxt1;
|
tableT4.Name = classEleTxt1;
|
||||||
|
|
||||||
var fieldEleTxt = GetElement(classText, string.Empty, "get", ref classTextIndex);
|
var fieldEleTxt = GetElement(classText, string.Empty, "get", ref classTextIndex);
|
||||||
while (!string.IsNullOrEmpty(fieldEleTxt))
|
while (!string.IsNullOrEmpty(fieldEleTxt))
|
||||||
{
|
{
|
||||||
var tempFieldEleTxt = fieldEleTxt;
|
var tempFieldEleTxt = fieldEleTxt;
|
||||||
var tempFieldEleIndex = 0;
|
var tempFieldEleIndex = 0;
|
||||||
|
|
||||||
FieldT4 fieldT4 = new FieldT4();
|
FieldT4 fieldT4 = new FieldT4();
|
||||||
tableT4.Fields.Add(fieldT4);
|
tableT4.Fields.Add(fieldT4);
|
||||||
|
|
||||||
var fieldAttrTxt = GetElement(tempFieldEleTxt, "[", "]", ref tempFieldEleIndex);
|
var fieldAttrTxt = GetElement(tempFieldEleTxt, "[", "]", ref tempFieldEleIndex);
|
||||||
while (!string.IsNullOrEmpty(fieldAttrTxt))
|
while (!string.IsNullOrEmpty(fieldAttrTxt))
|
||||||
{
|
{
|
||||||
fieldT4.Attrs.Add(fieldAttrTxt);
|
fieldT4.Attrs.Add(fieldAttrTxt);
|
||||||
fieldAttrTxt = GetElement(tempFieldEleTxt, "[", "]", ref tempFieldEleIndex);
|
fieldAttrTxt = GetElement(tempFieldEleTxt, "[", "]", ref tempFieldEleIndex);
|
||||||
}
|
}
|
||||||
var fieldEleTxt1 = GetElement(tempFieldEleTxt, "public", "{", ref tempFieldEleIndex);
|
var fieldEleTxt1 = GetElement(tempFieldEleTxt, "public", "{", ref tempFieldEleIndex);
|
||||||
if (!string.IsNullOrEmpty(fieldEleTxt1))
|
if (!string.IsNullOrEmpty(fieldEleTxt1))
|
||||||
{
|
{
|
||||||
var fieldEles=fieldEleTxt1.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
|
var fieldEles=fieldEleTxt1.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (fieldEles.Length > 0){
|
if (fieldEles.Length > 0){
|
||||||
fieldT4.Name = fieldEles[fieldEles.Length - 1];
|
fieldT4.Name = fieldEles[fieldEles.Length - 1];
|
||||||
if (string.Compare(fieldEles[0], "String", true) == 0)
|
if (string.Compare(fieldEles[0], "String", true) == 0)
|
||||||
{
|
{
|
||||||
if (!fieldT4.Attrs.Any(t => t.StartsWith("DataFieldLength")))
|
if (!fieldT4.Attrs.Any(t => t.StartsWith("DataFieldLength")))
|
||||||
fieldT4.Attrs.Add("DataFieldLength(500)");
|
fieldT4.Attrs.Add("DataFieldLength(500)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fieldEleTxt = GetElement(classText, "", "get", ref classTextIndex);
|
fieldEleTxt = GetElement(classText, "", "get", ref classTextIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var t4 in tables)
|
foreach(var t4 in tables)
|
||||||
{
|
{
|
||||||
if(t4.IgnoreT4) continue;
|
if(t4.IgnoreT4) continue;
|
||||||
var newName = t4.Name.ToLower();
|
var newName = t4.Name.ToLower();
|
||||||
var newNameAry = newName.Split(new char[] { '_' });
|
var newNameAry = newName.Split(new char[] { '_' });
|
||||||
if (newNameAry.Any() && newNameAry.Length >= 2)
|
if (newNameAry.Any() && newNameAry.Length >= 2)
|
||||||
{
|
{
|
||||||
t4.ModuleName = newNameAry[1].ToUpper();
|
t4.ModuleName = newNameAry[1].ToUpper();
|
||||||
for (var n = 2; n < newNameAry.Length; n++)
|
for (var n = 2; n < newNameAry.Length; n++)
|
||||||
{
|
{
|
||||||
t4.FixName += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(newNameAry[n]);
|
t4.FixName += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(newNameAry[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(string.IsNullOrEmpty(t4.ModuleName)||string.IsNullOrEmpty(t4.FixName))continue;
|
if(string.IsNullOrEmpty(t4.ModuleName)||string.IsNullOrEmpty(t4.FixName))continue;
|
||||||
if(!modules.Any(i=>i==t4.TableNameSpace)){
|
if(!modules.Any(i=>i==t4.TableNameSpace)){
|
||||||
modules.Add(t4.TableNameSpace);
|
modules.Add(t4.TableNameSpace);
|
||||||
}
|
}
|
||||||
if (t4.Attrs.Any())
|
if (t4.Attrs.Any())
|
||||||
{
|
{
|
||||||
foreach(var classAttr in t4.Attrs)
|
foreach(var classAttr in t4.Attrs)
|
||||||
{
|
{
|
||||||
if (classAttr.IndexOf("DataClassIndex", StringComparison.OrdinalIgnoreCase) > -1)
|
if (classAttr.IndexOf("DataClassIndex", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
List<string> indexFields = new List<string>();
|
List<string> indexFields = new List<string>();
|
||||||
bool isUnique = false;
|
bool isUnique = false;
|
||||||
var p1 = GetAttrParam(classAttr);
|
var p1 = GetAttrParam(classAttr);
|
||||||
int p1Index = 0;
|
int p1Index = 0;
|
||||||
var indexStr = GetElement(p1, "{", "}", ref p1Index);
|
var indexStr = GetElement(p1, "{", "}", ref p1Index);
|
||||||
if (!string.IsNullOrEmpty(indexStr))
|
if (!string.IsNullOrEmpty(indexStr))
|
||||||
indexFields.AddRange(indexStr.Split(new char[]{ ','}));
|
indexFields.AddRange(indexStr.Split(new char[]{ ','}));
|
||||||
var unqStr = GetElement(p1, ",", "", ref p1Index);
|
var unqStr = GetElement(p1, ",", "", ref p1Index);
|
||||||
isUnique = ToBoolean(unqStr);
|
isUnique = ToBoolean(unqStr);
|
||||||
if (indexFields.Any())
|
if (indexFields.Any())
|
||||||
t4.MapDatas.Add("builder.HasIndex(" + (string.Join(",", indexFields)) + ")" + (isUnique ? ".IsUnique()" : "") + ";");
|
t4.MapDatas.Add("builder.HasIndex(" + (string.Join(",", indexFields)) + ")" + (isUnique ? ".IsUnique()" : "") + ";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t4.Fields.Any())
|
if (t4.Fields.Any())
|
||||||
{
|
{
|
||||||
foreach(var f in t4.Fields)
|
foreach(var f in t4.Fields)
|
||||||
{
|
{
|
||||||
if (!f.Attrs.Any()) continue;
|
if (!f.Attrs.Any()) continue;
|
||||||
if (f.Attrs.Any(t => t.IndexOf("DataFieldIngore", StringComparison.OrdinalIgnoreCase) > -1))
|
if (f.Attrs.Any(t => t.IndexOf("DataFieldIngore", StringComparison.OrdinalIgnoreCase) > -1))
|
||||||
{
|
{
|
||||||
t4.MapDatas.Add("builder.Ignore(t => t." + f.Name + ");");
|
t4.MapDatas.Add("builder.Ignore(t => t." + f.Name + ");");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var fAttr in f.Attrs)
|
foreach (var fAttr in f.Attrs)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fAttr.IndexOf("DataFieldLength", StringComparison.OrdinalIgnoreCase) > -1)
|
if (fAttr.IndexOf("DataFieldLength", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
var p1 = GetAttrParams(fAttr);
|
var p1 = GetAttrParams(fAttr);
|
||||||
if (p1 != null && p1.Any())
|
if (p1 != null && p1.Any())
|
||||||
t4.MapDatas.Add("builder.Property(t => t." + f.Name + ").HasMaxLength(" + p1[0] + ");");
|
t4.MapDatas.Add("builder.Property(t => t." + f.Name + ").HasMaxLength(" + p1[0] + ");");
|
||||||
}
|
}
|
||||||
else if (fAttr.IndexOf("DataFieldIndex", StringComparison.OrdinalIgnoreCase) > -1)
|
else if (fAttr.IndexOf("DataFieldIndex", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
var p1 = GetAttrParams(fAttr);
|
var p1 = GetAttrParams(fAttr);
|
||||||
bool isUnique = p1 != null && p1.Length > 0 ? ToBoolean(p1[0]) : false;
|
bool isUnique = p1 != null && p1.Length > 0 ? ToBoolean(p1[0]) : false;
|
||||||
if(isUnique){
|
if(isUnique){
|
||||||
string indexStr="builder.HasIndex(\""+ f.Name + "\"";
|
string indexStr="builder.HasIndex(\""+ f.Name + "\"";
|
||||||
for(var x=1;x<p1.Length;x++){
|
for(var x=1;x<p1.Length;x++){
|
||||||
var nextField=p1[x];
|
var nextField=p1[x];
|
||||||
indexStr+=",\""+nextField+"\"";
|
indexStr+=",\""+nextField+"\"";
|
||||||
}
|
}
|
||||||
indexStr+=").IsUnique();";
|
indexStr+=").IsUnique();";
|
||||||
t4.MapDatas.Add(indexStr);
|
t4.MapDatas.Add(indexStr);
|
||||||
}else{
|
}else{
|
||||||
t4.MapDatas.Add("builder.HasIndex(\""+ f.Name + "\");");
|
t4.MapDatas.Add("builder.HasIndex(\""+ f.Name + "\");");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (fAttr.IndexOf("DataFieldForeignKey", StringComparison.OrdinalIgnoreCase) > -1)
|
else if (fAttr.IndexOf("DataFieldForeignKey", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
var p1 = GetAttrParams(fAttr);
|
var p1 = GetAttrParams(fAttr);
|
||||||
if(p1!=null&& p1.Length>0)
|
if(p1!=null&& p1.Length>0)
|
||||||
{
|
{
|
||||||
var nav = p1[0];
|
var nav = p1[0];
|
||||||
var master = p1.Length > 1 ? p1[1] : string.Empty;
|
var master = p1.Length > 1 ? p1[1] : string.Empty;
|
||||||
var isOneOnOne=false;
|
var isOneOnOne=false;
|
||||||
if(master=="true"||master=="false"){
|
if(master=="true"||master=="false"){
|
||||||
isOneOnOne=bool.Parse(master);
|
isOneOnOne=bool.Parse(master);
|
||||||
master="";
|
master="";
|
||||||
}
|
}
|
||||||
if(p1.Length>2){
|
if(p1.Length>2){
|
||||||
isOneOnOne=bool.Parse(p1[2]);
|
isOneOnOne=bool.Parse(p1[2]);
|
||||||
}
|
}
|
||||||
if(!isOneOnOne)
|
if(!isOneOnOne)
|
||||||
{
|
{
|
||||||
t4.MapDatas.Add("builder.HasOne(t => t." + nav + ").WithMany(" + (string.IsNullOrEmpty(master) ? "" : ("t=>t." + master)) + ").HasForeignKey(t => t." + f.Name + ").OnDelete(DeleteBehavior.Restrict);");
|
t4.MapDatas.Add("builder.HasOne(t => t." + nav + ").WithMany(" + (string.IsNullOrEmpty(master) ? "" : ("t=>t." + master)) + ").HasForeignKey(t => t." + f.Name + ").OnDelete(DeleteBehavior.Restrict);");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
t4.MapDatas.Add("builder.HasOne(t => t." + nav + ").WithOne(" + (string.IsNullOrEmpty(master) ? "" : ("t=>t." + master)) + ").HasForeignKey<"+t4.Name+">(t => t." + f.Name + ").OnDelete(DeleteBehavior.Restrict);");
|
t4.MapDatas.Add("builder.HasOne(t => t." + nav + ").WithOne(" + (string.IsNullOrEmpty(master) ? "" : ("t=>t." + master)) + ").HasForeignKey<"+t4.Name+">(t => t." + f.Name + ").OnDelete(DeleteBehavior.Restrict);");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (fAttr.IndexOf("UnionForeignKey", StringComparison.OrdinalIgnoreCase) > -1)
|
else if (fAttr.IndexOf("UnionForeignKey", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
var p1 = GetAttrParams(fAttr);
|
var p1 = GetAttrParams(fAttr);
|
||||||
if(p1!=null&& p1.Length>0)
|
if(p1!=null&& p1.Length>0)
|
||||||
{
|
{
|
||||||
var forginkeys = p1[0].Split('|');
|
var forginkeys = p1[0].Split('|');
|
||||||
var forginkey = $"t.{string.Join(",t.", forginkeys)}";
|
var forginkey = $"t.{string.Join(",t.", forginkeys)}";
|
||||||
var master = p1.Length > 1 ? p1[1] : string.Empty;
|
var master = p1.Length > 1 ? p1[1] : string.Empty;
|
||||||
t4.MapDatas.Add("builder.HasOne(t => t." + f.Name + ").WithMany(" + (string.IsNullOrEmpty(master) ? "" : ("t=>t." + master)) + ").HasForeignKey(t => new { " + forginkey + " });");
|
t4.MapDatas.Add("builder.HasOne(t => t." + f.Name + ").WithMany(" + (string.IsNullOrEmpty(master) ? "" : ("t=>t." + master)) + ").HasForeignKey(t => new { " + forginkey + " });");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (fAttr.IndexOf("DataFieldForeignKeyForMaster", StringComparison.OrdinalIgnoreCase) > -1)
|
else if (fAttr.IndexOf("DataFieldForeignKeyForMaster", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
{
|
{
|
||||||
var p1 = GetAttrParams(fAttr);
|
var p1 = GetAttrParams(fAttr);
|
||||||
if (p1 != null && p1.Length > 0)
|
if (p1 != null && p1.Length > 0)
|
||||||
{
|
{
|
||||||
var id = p1[0];
|
var id = p1[0];
|
||||||
var nav = p1.Length > 1 ? p1[1] : string.Empty;
|
var nav = p1.Length > 1 ? p1[1] : string.Empty;
|
||||||
var isOneOnOne=false;
|
var isOneOnOne=false;
|
||||||
if(nav=="true"||nav=="false"){
|
if(nav=="true"||nav=="false"){
|
||||||
isOneOnOne=bool.Parse(nav);
|
isOneOnOne=bool.Parse(nav);
|
||||||
nav="";
|
nav="";
|
||||||
}
|
}
|
||||||
if(p1.Length>2){
|
if(p1.Length>2){
|
||||||
isOneOnOne=bool.Parse(p1[2]);
|
isOneOnOne=bool.Parse(p1[2]);
|
||||||
}
|
}
|
||||||
if(!isOneOnOne)
|
if(!isOneOnOne)
|
||||||
t4.MapDatas.Add("builder.HasMany(t => t." + f.Name + ").WithOne(" + (string.IsNullOrEmpty(nav) ? "" : ("t=>t." + nav)) + ").HasForeignKey(t => t." + id+ ").OnDelete(DeleteBehavior.Restrict);");
|
t4.MapDatas.Add("builder.HasMany(t => t." + f.Name + ").WithOne(" + (string.IsNullOrEmpty(nav) ? "" : ("t=>t." + nav)) + ").HasForeignKey(t => t." + id+ ").OnDelete(DeleteBehavior.Restrict);");
|
||||||
else
|
else
|
||||||
t4.MapDatas.Add("builder.HasOne(t => t." + f.Name + ").WithOne(" + (string.IsNullOrEmpty(nav) ? "" : ("t=>t." + nav)) + ").HasForeignKey(t => t." + id+ ").OnDelete(DeleteBehavior.Restrict);");
|
t4.MapDatas.Add("builder.HasOne(t => t." + f.Name + ").WithOne(" + (string.IsNullOrEmpty(nav) ? "" : ("t=>t." + nav)) + ").HasForeignKey(t => t." + id+ ").OnDelete(DeleteBehavior.Restrict);");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var space in modules)
|
foreach(var space in modules)
|
||||||
{
|
{
|
||||||
WriteLine("using "+space +";");
|
WriteLine("using "+space +";");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach(var t4 in tables)
|
foreach(var t4 in tables)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(t4.ModuleName)||string.IsNullOrEmpty(t4.FixName)||t4.IgnoreT4)continue;
|
if(string.IsNullOrEmpty(t4.ModuleName)||string.IsNullOrEmpty(t4.FixName)||t4.IgnoreT4)continue;
|
||||||
#>
|
#>
|
||||||
#region <#= t4.FixName#>
|
#region <#= t4.FixName#>
|
||||||
public partial class <#= t4.ModuleName#><#= t4.FixName#>Map :<#=t4.BaseEntityName#><<#= t4.Name#>>
|
public partial class <#= t4.ModuleName#><#= t4.FixName#>Map :<#=t4.BaseEntityName#><<#= t4.Name#>>
|
||||||
{
|
{
|
||||||
public override void Configure(EntityTypeBuilder<<#= t4.Name#>> builder)
|
public override void Configure(EntityTypeBuilder<<#= t4.Name#>> builder)
|
||||||
{
|
{
|
||||||
base.Configure(builder);
|
base.Configure(builder);
|
||||||
<#
|
<#
|
||||||
if(t4.MapDatas.Any())
|
if(t4.MapDatas.Any())
|
||||||
{
|
{
|
||||||
foreach(var d in t4.MapDatas)
|
foreach(var d in t4.MapDatas)
|
||||||
{
|
{
|
||||||
WriteLine(d);
|
WriteLine(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#>
|
#>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
<#}
|
<#}
|
||||||
#>
|
#>
|
||||||
}
|
}
|
||||||
|
|
||||||
<#+
|
<#+
|
||||||
|
|
||||||
class TableT4
|
class TableT4
|
||||||
{
|
{
|
||||||
public string TableNameSpace { get; set; }
|
public string TableNameSpace { get; set; }
|
||||||
public string ModuleName { get; set; }
|
public string ModuleName { get; set; }
|
||||||
public string FixName { get; set; }
|
public string FixName { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string BaseName { get; set; }
|
public string BaseName { get; set; }
|
||||||
public string BaseEntityName{get;set;}
|
public string BaseEntityName{get;set;}
|
||||||
public bool IgnoreT4{get;set;}
|
public bool IgnoreT4{get;set;}
|
||||||
public List<FieldT4> Fields = new List<FieldT4>();
|
public List<FieldT4> Fields = new List<FieldT4>();
|
||||||
public List<string> MapDatas = new List<string>();
|
public List<string> MapDatas = new List<string>();
|
||||||
public List<string> Attrs = new List<string>();
|
public List<string> Attrs = new List<string>();
|
||||||
public TableT4()
|
public TableT4()
|
||||||
{
|
{
|
||||||
MapDatas = new List<string>();
|
MapDatas = new List<string>();
|
||||||
Fields = new List<FieldT4>();
|
Fields = new List<FieldT4>();
|
||||||
Attrs = new List<string>();
|
Attrs = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FieldT4
|
class FieldT4
|
||||||
{
|
{
|
||||||
public FieldT4()
|
public FieldT4()
|
||||||
{
|
{
|
||||||
Attrs = new List<string>();
|
Attrs = new List<string>();
|
||||||
}
|
}
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public List<string> Attrs = new List<string>();
|
public List<string> Attrs = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetElement(string txt,string startStr,string endStr, ref int index)
|
private static string GetElement(string txt,string startStr,string endStr, ref int index)
|
||||||
{
|
{
|
||||||
var tempStartIndex=string.IsNullOrEmpty(startStr)?index:
|
var tempStartIndex=string.IsNullOrEmpty(startStr)?index:
|
||||||
txt.IndexOf(startStr, index, StringComparison.OrdinalIgnoreCase);
|
txt.IndexOf(startStr, index, StringComparison.OrdinalIgnoreCase);
|
||||||
var tempEndIndex = string.IsNullOrEmpty(endStr) ? txt.Length : txt.IndexOf(endStr, index, StringComparison.OrdinalIgnoreCase);
|
var tempEndIndex = string.IsNullOrEmpty(endStr) ? txt.Length : txt.IndexOf(endStr, index, StringComparison.OrdinalIgnoreCase);
|
||||||
if (tempStartIndex != -1&&tempEndIndex!=-1)
|
if (tempStartIndex != -1&&tempEndIndex!=-1)
|
||||||
{
|
{
|
||||||
if (tempStartIndex > tempEndIndex)
|
if (tempStartIndex > tempEndIndex)
|
||||||
tempEndIndex = string.IsNullOrEmpty(endStr) ? txt.Length :
|
tempEndIndex = string.IsNullOrEmpty(endStr) ? txt.Length :
|
||||||
txt.IndexOf(endStr, tempStartIndex , StringComparison.OrdinalIgnoreCase);
|
txt.IndexOf(endStr, tempStartIndex , StringComparison.OrdinalIgnoreCase);
|
||||||
var tempStartIndex1 = string.IsNullOrEmpty(startStr) ? -1 :
|
var tempStartIndex1 = string.IsNullOrEmpty(startStr) ? -1 :
|
||||||
txt.IndexOf(startStr, tempStartIndex+1, StringComparison.OrdinalIgnoreCase);
|
txt.IndexOf(startStr, tempStartIndex+1, StringComparison.OrdinalIgnoreCase);
|
||||||
if (tempStartIndex1 != -1&&tempStartIndex1< tempEndIndex)
|
if (tempStartIndex1 != -1&&tempStartIndex1< tempEndIndex)
|
||||||
tempEndIndex = string.IsNullOrEmpty(endStr) ? txt.Length :
|
tempEndIndex = string.IsNullOrEmpty(endStr) ? txt.Length :
|
||||||
txt.IndexOf(endStr, tempEndIndex+1, StringComparison.OrdinalIgnoreCase);
|
txt.IndexOf(endStr, tempEndIndex+1, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
int startStrLength = (string.IsNullOrEmpty(startStr) ? 0 : startStr.Length);
|
int startStrLength = (string.IsNullOrEmpty(startStr) ? 0 : startStr.Length);
|
||||||
int endStrLength = (string.IsNullOrEmpty(endStr) ? 0 : endStr.Length);
|
int endStrLength = (string.IsNullOrEmpty(endStr) ? 0 : endStr.Length);
|
||||||
index = tempEndIndex + endStrLength;
|
index = tempEndIndex + endStrLength;
|
||||||
string ret= txt.Substring(tempStartIndex+startStrLength, tempEndIndex-tempStartIndex- startStrLength);
|
string ret= txt.Substring(tempStartIndex+startStrLength, tempEndIndex-tempStartIndex- startStrLength);
|
||||||
return ret.Trim();
|
return ret.Trim();
|
||||||
}
|
}
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static string GetAttrParam(string str)
|
private static string GetAttrParam(string str)
|
||||||
{
|
{
|
||||||
int lefIndex = str.IndexOf("(");
|
int lefIndex = str.IndexOf("(");
|
||||||
int rigthIndex = str.LastIndexOf(")");
|
int rigthIndex = str.LastIndexOf(")");
|
||||||
if(lefIndex!=-1&&rigthIndex!=-1)
|
if(lefIndex!=-1&&rigthIndex!=-1)
|
||||||
{
|
{
|
||||||
var ret= str.Substring(lefIndex + 1, rigthIndex - 1- lefIndex);
|
var ret= str.Substring(lefIndex + 1, rigthIndex - 1- lefIndex);
|
||||||
return ret.Trim();
|
return ret.Trim();
|
||||||
}
|
}
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string[] GetAttrParams(string str)
|
private static string[] GetAttrParams(string str)
|
||||||
{
|
{
|
||||||
var ret = GetAttrParam(str);
|
var ret = GetAttrParam(str);
|
||||||
if (string.IsNullOrEmpty(ret)) return null;
|
if (string.IsNullOrEmpty(ret)) return null;
|
||||||
return ret.Split(',').Select(t => t.Trim().Replace("\"", "")).ToArray();
|
return ret.Split(',').Select(t => t.Trim().Replace("\"", "")).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ToBoolean(string str)
|
private static bool ToBoolean(string str)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str)) return false;
|
if (string.IsNullOrEmpty(str)) return false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Convert.ToBoolean(str);
|
return Convert.ToBoolean(str);
|
||||||
}catch{
|
}catch{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void GetFileName(List<string> filePaths, string path)
|
public static void GetFileName(List<string> filePaths, string path)
|
||||||
{
|
{
|
||||||
DirectoryInfo root = new DirectoryInfo(path);
|
DirectoryInfo root = new DirectoryInfo(path);
|
||||||
foreach (FileInfo f in root.GetFiles())
|
foreach (FileInfo f in root.GetFiles())
|
||||||
{
|
{
|
||||||
if (f.Extension.ToLower()==".cs".ToLower())
|
if (f.Extension.ToLower()==".cs".ToLower())
|
||||||
{
|
{
|
||||||
filePaths.Add(f.FullName);
|
filePaths.Add(f.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (DirectoryInfo d in root.GetDirectories())
|
foreach (DirectoryInfo d in root.GetDirectories())
|
||||||
{
|
{
|
||||||
GetFileName(filePaths, d.FullName);
|
GetFileName(filePaths, d.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#>
|
#>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user