OA项目Spring.Net代替抽象工厂(三)

网友投稿 266 2022-09-04

OA项目Spring.Net代替抽象工厂(三)

Servrvice层的代码:

Dal层代码:

-->

获取数据库的所有表:

exec sp_tables

拿到表中的列:

exec sp_columns users

查看数据库名称:

exec sp_databases

T4模板的使用:

SunOA.IDAL下:IDals

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using SunOA.Model;namespace SunOA.IDAL{ <#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> public partial interface I<#=entity.Name#>Dal : IBaseDal<<#=entity.Name#>> { } <#}#>}

IDbSession.tt

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>namespace SunOA.IDAL{ public partial interface IDbSession { <#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> I<#=entity.Name#>Dal <#=entity.Name#>Dal { get;}<#}#> }}

SunOA.EFDAL.Dals

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Linq.Expressions;using System.Text;using System.Threading.Tasks;using SunOA.IDAL;using SunOA.Model;namespace SunOA.EFDAL{ <#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> public partial class <#=entity.Name#>Dal:BaseDal<<#=entity.Name#>>,I<#=entity.Name#>Dal { }<#}#>}

DbSession.tt

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>using SunOA.EFDAL;using SunOA.IDAL;namespace SunOA.DALFactory{ public partial class DbSession :IDbSession { <#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> public I<#=entity.Name#>Dal <#=entity.Name#>Dal { get { return StaticDalFactory.Get<#=entity.Name#>Dal(); } }<#}#> }}

StaticDalFactory

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;using System.Web;using SunOA.EFDAL;using SunOA.IDAL;using SunOA.NHDAL;namespace SunOA.DALFactory{ public partial class StaticDalFactory { <#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> public static I<#=entity.Name#>Dal Get<#=entity.Name#>Dal() { return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".<#=entity.Name#>Dal") as I<#=entity.Name#>Dal; }<#}#> }}

IBLL.IServices

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using SunOA.Model;namespace SunOA.IBLL{<#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> public partial interface I<#=entity.Name#>Service:IBaseService<<#=entity.Name#>> { }<#}#>}

IBLL.ServerXmlSpring

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".xml"#><#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>Service" type="SunOA.BLL.<#=entity.Name#>Service, SunOA.BLL" singleton="false" > <#}#>

BLL.Services

<#@ template language="C#" debug="false" hostspecific="true"#><#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#> <#CodeGenerationTools code = new CodeGenerationTools(this);MetadataLoader loader = new MetadataLoader(this);CodeRegion region = new CodeRegion(this, 1);MetadataTools ef = new MetadataTools(this);string inputFile = @"..\\SunOA.Model\\DataModel.edmx";EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);string namespaceName = code.VsNamespaceSuggestion();EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);#>using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using SunOA.DALFactory;using SunOA.EFDAL;using SunOA.IBLL;using SunOA.IDAL;using SunOA.Model;using SunOA.NHDAL;namespace SunOA.BLL{<#foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name)){ #> public partial class <#=entity.Name#>Service:BaseService<<#=entity.Name#>>,I<#=entity.Name#>Service //crud { public override void SetCurrentDal() { CurrentDal = DbSession.<#=entity.Name#>Dal; } }<#}#>}

添加类的时候,生成转换所有的T4模板。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Redis AOF持久化(二)
下一篇:JAVA简易数据连接池Condition
相关文章

 发表评论

暂时没有评论,来抢沙发吧~