mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
DbFirst Support Razor Template
This commit is contained in:
parent
2ee1589e24
commit
91213483aa
@ -8,6 +8,6 @@ namespace ExtensionsDemo
|
|||||||
{
|
{
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static string ConnectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest";
|
public static string ConnectionString = "server=.;uid=sa;pwd=haosql;database=SqlSugar4XTest";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
Src/Asp.Net/ExtensionsDemo/DbFirstDemo.cs
Normal file
30
Src/Asp.Net/ExtensionsDemo/DbFirstDemo.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using SqlSugar.DbFirstExtensions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ExtensionsDemo
|
||||||
|
{
|
||||||
|
public class DbFirstDemo
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
ConfigureExternalServices = new ConfigureExternalServices()
|
||||||
|
{
|
||||||
|
RazorService = new RazorService()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
db.DbFirst.UseRazorAnalysis(RazorFirst.DefaultRazorClassTemplate).CreateClassFile("c:\\Demo\\Razor\\");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -45,11 +45,16 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CacheDemo.cs" />
|
<Compile Include="CacheDemo.cs" />
|
||||||
<Compile Include="Config.cs" />
|
<Compile Include="Config.cs" />
|
||||||
|
<Compile Include="DbFirstDemo.cs" />
|
||||||
<Compile Include="Models\Student.cs" />
|
<Compile Include="Models\Student.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SqlSugar.DbFirstExtensions\SqlSugar.DbFirstExtensions.csproj">
|
||||||
|
<Project>{629cdf51-682f-4b22-843a-ba76c232accd}</Project>
|
||||||
|
<Name>SqlSugar.DbFirstExtensions</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\SqlSugar.Extensions.DataCache\SqlSugar.Extensions.DataCache.csproj">
|
<ProjectReference Include="..\SqlSugar.Extensions.DataCache\SqlSugar.Extensions.DataCache.csproj">
|
||||||
<Project>{cdb72abe-0336-4730-a195-abf2611deeaa}</Project>
|
<Project>{cdb72abe-0336-4730-a195-abf2611deeaa}</Project>
|
||||||
<Name>SqlSugar.Extensions.DataCache</Name>
|
<Name>SqlSugar.Extensions.DataCache</Name>
|
||||||
|
@ -11,6 +11,7 @@ namespace ExtensionsDemo
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
CacheDemo.Init();
|
CacheDemo.Init();
|
||||||
|
DbFirstDemo.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// 有关程序集的一般信息由以下
|
||||||
|
// 控制。更改这些特性值可修改
|
||||||
|
// 与程序集关联的信息。
|
||||||
|
[assembly: AssemblyTitle("SqlSugar.DbFirstExtensions")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("SqlSugar.DbFirstExtensions")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||||
|
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||||
|
//请将此类型的 ComVisible 特性设置为 true。
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||||
|
[assembly: Guid("629cdf51-682f-4b22-843a-ba76c232accd")]
|
||||||
|
|
||||||
|
// 程序集的版本信息由下列四个值组成:
|
||||||
|
//
|
||||||
|
// 主版本
|
||||||
|
// 次版本
|
||||||
|
// 生成号
|
||||||
|
// 修订号
|
||||||
|
//
|
||||||
|
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||||
|
//通过使用 "*",如下所示:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
40
Src/Asp.Net/SqlSugar.DbFirstExtensions/RazorService.cs
Normal file
40
Src/Asp.Net/SqlSugar.DbFirstExtensions/RazorService.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using RazorEngine;
|
||||||
|
using RazorEngine.Templating;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar.DbFirstExtensions
|
||||||
|
{
|
||||||
|
public class RazorService : IRazorService
|
||||||
|
{
|
||||||
|
public List<KeyValuePair<string,string>> GetClassStringList(string razorTemplate, List<RazorTableInfo> model)
|
||||||
|
{
|
||||||
|
if (model != null && model.Any())
|
||||||
|
{
|
||||||
|
var result = new List<KeyValuePair<string, string>>();
|
||||||
|
foreach (var item in model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
item.ClassName = item.DbTableName;//Format Class Name
|
||||||
|
string key = "RazorService.GetClassStringList"+ razorTemplate.Length;
|
||||||
|
var classString = Engine.Razor.RunCompile(razorTemplate, key, item.GetType(), item);
|
||||||
|
result.Add(new KeyValuePair<string,string>(item.ClassName,classString));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
new Exception(item.DbTableName + " error ." + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new List<KeyValuePair<string, string>> ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{629CDF51-682F-4B22-843A-BA76C232ACCD}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>SqlSugar.DbFirstExtensions</RootNamespace>
|
||||||
|
<AssemblyName>SqlSugar.DbFirstExtensions</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="RazorEngine, Version=3.10.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\RazorEngine.3.10.0\lib\net45\RazorEngine.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="RazorService.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
|
||||||
|
<Project>{489bb790-226c-4fad-8d1e-51d72a7ff8e5}</Project>
|
||||||
|
<Name>SqlSugar</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
5
Src/Asp.Net/SqlSugar.DbFirstExtensions/packages.config
Normal file
5
Src/Asp.Net/SqlSugar.DbFirstExtensions/packages.config
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
|
||||||
|
<package id="RazorEngine" version="3.10.0" targetFramework="net45" />
|
||||||
|
</packages>
|
@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSugar.Extensions.DataCac
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NugetTest", "NugetTest\NugetTest.csproj", "{A7202527-A5CC-4F9B-B8F2-63520892F01D}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NugetTest", "NugetTest\NugetTest.csproj", "{A7202527-A5CC-4F9B-B8F2-63520892F01D}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSugar.DbFirstExtensions", "SqlSugar.DbFirstExtensions\SqlSugar.DbFirstExtensions.csproj", "{629CDF51-682F-4B22-843A-BA76C232ACCD}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -65,6 +67,10 @@ Global
|
|||||||
{A7202527-A5CC-4F9B-B8F2-63520892F01D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A7202527-A5CC-4F9B-B8F2-63520892F01D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A7202527-A5CC-4F9B-B8F2-63520892F01D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A7202527-A5CC-4F9B-B8F2-63520892F01D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A7202527-A5CC-4F9B-B8F2-63520892F01D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A7202527-A5CC-4F9B-B8F2-63520892F01D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{629CDF51-682F-4B22-843A-BA76C232ACCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{629CDF51-682F-4B22-843A-BA76C232ACCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{629CDF51-682F-4B22-843A-BA76C232ACCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{629CDF51-682F-4B22-843A-BA76C232ACCD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -72,6 +78,7 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{EBBA686A-C1F0-4823-85EB-32EB306ADD7F} = {B762D1DA-DFCD-4597-A14D-4F20DA0EE70E}
|
{EBBA686A-C1F0-4823-85EB-32EB306ADD7F} = {B762D1DA-DFCD-4597-A14D-4F20DA0EE70E}
|
||||||
{CDB72ABE-0336-4730-A195-ABF2611DEEAA} = {B762D1DA-DFCD-4597-A14D-4F20DA0EE70E}
|
{CDB72ABE-0336-4730-A195-ABF2611DEEAA} = {B762D1DA-DFCD-4597-A14D-4F20DA0EE70E}
|
||||||
|
{629CDF51-682F-4B22-843A-BA76C232ACCD} = {B762D1DA-DFCD-4597-A14D-4F20DA0EE70E}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {AE9BE6D6-3952-4582-B65E-83E0E57FDC8A}
|
SolutionGuid = {AE9BE6D6-3952-4582-B65E-83E0E57FDC8A}
|
||||||
|
@ -89,10 +89,54 @@ namespace SqlSugar
|
|||||||
this.PropertyTemplate = func(this.PropertyTemplate);
|
this.PropertyTemplate = func(this.PropertyTemplate);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public DbRazor SettingTemplate(string templatePath)
|
public RazorFirst UseRazorAnalysis(string razorClassTemplate,string classNamespace="Models" )
|
||||||
{
|
{
|
||||||
Check.Exception(true, ErrorMessage.GetThrowMessage("Use db.DbFirst.LoadTemplate('c:\\template.txt').CreateClassFile(classDirectoryPath) Nuget Install SqlSugar.DbFirstRazor ", "当前方法已经过期,请使用 db.DbFirst.LoadTemplate('c:\\template.txt').CreateClassFile(classDirectoryPath) Nuget 安装 SqlSugar.DbFirstRazor "));
|
if (razorClassTemplate == null)
|
||||||
return null;
|
{
|
||||||
|
razorClassTemplate = "";
|
||||||
|
}
|
||||||
|
razorClassTemplate=razorClassTemplate.Replace("@Model.Namespace", classNamespace);
|
||||||
|
var result = new RazorFirst();
|
||||||
|
if (this.Context.CurrentConnectionConfig.ConfigureExternalServices?.RazorService != null)
|
||||||
|
{
|
||||||
|
List<RazorTableInfo> razorList = new List<RazorTableInfo>();
|
||||||
|
var tables = this.Context.DbMaintenance.GetTableInfoList(false);
|
||||||
|
if (tables.HasValue())
|
||||||
|
{
|
||||||
|
foreach (var item in tables)
|
||||||
|
{
|
||||||
|
var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(item.Name, false);
|
||||||
|
RazorTableInfo table = new RazorTableInfo()
|
||||||
|
{
|
||||||
|
Columns = columns.Select(it => new RazorColumnInfo()
|
||||||
|
{
|
||||||
|
ColumnDescription = it.ColumnDescription,
|
||||||
|
DataType = it.DataType,
|
||||||
|
DbColumnName = it.DbColumnName,
|
||||||
|
DefaultValue = it.DefaultValue,
|
||||||
|
IsIdentity = it.IsIdentity,
|
||||||
|
IsNullable = it.IsNullable,
|
||||||
|
IsPrimarykey = it.IsPrimarykey,
|
||||||
|
Length = it.Length
|
||||||
|
}).ToList(),
|
||||||
|
Description = item.Description,
|
||||||
|
DbTableName = item.Name
|
||||||
|
};
|
||||||
|
foreach (var col in table.Columns)
|
||||||
|
{
|
||||||
|
col.DataType = GetPropertyTypeName(columns.First(it=>it.DbColumnName==col.DbColumnName));
|
||||||
|
}
|
||||||
|
razorList.Add(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.ClassStringList = this.Context.CurrentConnectionConfig.ConfigureExternalServices.RazorService.GetClassStringList(razorClassTemplate, razorList);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Check.Exception(true, ErrorMessage.GetThrowMessage("Need to achieve ConnectionConfig.ConfigureExternal Services.RazorService", "需要实现 ConnectionConfig.ConfigureExternal Services.RazorService接口"));
|
||||||
|
}
|
||||||
|
this.Context.Utilities.RemoveCacheAll();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -356,7 +400,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result += "?";
|
result += "?";
|
||||||
}
|
}
|
||||||
if (result == "Int32") {
|
if (result == "Int32")
|
||||||
|
{
|
||||||
result = "int";
|
result = "int";
|
||||||
}
|
}
|
||||||
if (result == "String")
|
if (result == "String")
|
||||||
@ -370,7 +415,8 @@ namespace SqlSugar
|
|||||||
var convertString = GetProertypeDefaultValue(item);
|
var convertString = GetProertypeDefaultValue(item);
|
||||||
if (convertString == "DateTime.Now" || convertString == null)
|
if (convertString == "DateTime.Now" || convertString == null)
|
||||||
return convertString;
|
return convertString;
|
||||||
if (convertString.ObjToString() == "newid()") {
|
if (convertString.ObjToString() == "newid()")
|
||||||
|
{
|
||||||
return "Guid.NewGuid()";
|
return "Guid.NewGuid()";
|
||||||
}
|
}
|
||||||
if (item.DataType == "bit")
|
if (item.DataType == "bit")
|
||||||
|
@ -1,15 +1,92 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public class DbRazor
|
public class RazorFirst
|
||||||
{
|
{
|
||||||
public void CreateClassFile(string directoryPath) {
|
internal List<KeyValuePair<string,string>> ClassStringList { get; set; }
|
||||||
|
|
||||||
|
public static string DefaultRazorClassTemplate =
|
||||||
|
@"using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using SqlSugar;
|
||||||
|
namespace @Model.Namespace
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
///
|
||||||
|
///</summary>
|
||||||
|
public partial class @Model.ClassName
|
||||||
|
{
|
||||||
|
public @(Model.ClassName)(){
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@foreach (var item in @Model.Columns)
|
||||||
|
{
|
||||||
|
if(item.IsPrimarykey&&item.IsIdentity){
|
||||||
|
@:/// <summary>
|
||||||
|
@:/// Desc:@item.ColumnDescription
|
||||||
|
@:/// Default:@item.DefaultValue
|
||||||
|
@:/// Nullable:@item.IsNullable
|
||||||
|
@:/// </summary>
|
||||||
|
@:[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
@:public @item.DataType @item.DbColumnName {get;set;}
|
||||||
|
}
|
||||||
|
else if(item.IsPrimarykey)
|
||||||
|
{
|
||||||
|
@:/// <summary>
|
||||||
|
@:/// Desc:@item.ColumnDescription
|
||||||
|
@:/// Default:@item.DefaultValue
|
||||||
|
@:/// Nullable:@item.IsNullable
|
||||||
|
@:/// </summary>
|
||||||
|
@:[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||||
|
@:public @item.DataType @item.DbColumnName {get;set;}
|
||||||
|
}
|
||||||
|
else if(item.IsIdentity)
|
||||||
|
{
|
||||||
|
@:/// <summary>
|
||||||
|
@:/// Desc:@item.ColumnDescription
|
||||||
|
@:/// Default:@item.DefaultValue
|
||||||
|
@:/// Nullable:@item.IsNullable
|
||||||
|
@:/// </summary>
|
||||||
|
@:[SqlSugar.SugarColumn(IsIdentity = true)]
|
||||||
|
@:public @item.DataType @item.DbColumnName {get;set;}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@:/// <summary>
|
||||||
|
@:/// Desc:@item.ColumnDescription
|
||||||
|
@:/// Default:@item.DefaultValue
|
||||||
|
@:/// Nullable:@item.IsNullable
|
||||||
|
@:/// </summary>
|
||||||
|
@:public @item.DataType @item.DbColumnName {get;set;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
public void CreateClassFile(string directoryPath)
|
||||||
|
{
|
||||||
|
var seChar = Path.DirectorySeparatorChar.ToString();
|
||||||
|
if (ClassStringList.HasValue())
|
||||||
|
{
|
||||||
|
foreach (var item in ClassStringList)
|
||||||
|
{
|
||||||
|
var filePath = directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format(seChar + "{0}.cs", item.Key);
|
||||||
|
FileHelper.CreateFile(filePath, item.Value, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<KeyValuePair<string, string>> GetClassStringList()
|
||||||
|
{
|
||||||
|
return ClassStringList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,19 @@ namespace SqlSugar
|
|||||||
private ISerializeService _SerializeService;
|
private ISerializeService _SerializeService;
|
||||||
private ICacheService _ReflectionInoCache;
|
private ICacheService _ReflectionInoCache;
|
||||||
private ICacheService _DataInfoCache;
|
private ICacheService _DataInfoCache;
|
||||||
|
private IRazorService _RazorService;
|
||||||
|
|
||||||
|
public IRazorService RazorService
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_RazorService == null)
|
||||||
|
return _RazorService;
|
||||||
|
else
|
||||||
|
return _RazorService;
|
||||||
|
}
|
||||||
|
set { _RazorService = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public ISerializeService SerializeService
|
public ISerializeService SerializeService
|
||||||
{
|
{
|
||||||
|
@ -11,4 +11,24 @@ namespace SqlSugar
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public DbObjectType DbObjectType { get; set; }
|
public DbObjectType DbObjectType { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RazorTableInfo
|
||||||
|
{
|
||||||
|
public string DbTableName { get; set; }
|
||||||
|
public string ClassName { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public DbObjectType DbObjectType { get; set; }
|
||||||
|
public List<RazorColumnInfo> Columns { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RazorColumnInfo {
|
||||||
|
public string DbColumnName { get; set; }
|
||||||
|
public string DataType { get; set; }
|
||||||
|
public int Length { get; set; }
|
||||||
|
public string ColumnDescription { get; set; }
|
||||||
|
public string DefaultValue { get; set; }
|
||||||
|
public bool IsNullable { get; set; }
|
||||||
|
public bool IsIdentity { get; set; }
|
||||||
|
public bool IsPrimarykey { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public interface IRazorService
|
||||||
|
{
|
||||||
|
List<KeyValuePair<string, string>> GetClassStringList(string razorTemplate, List<RazorTableInfo> model);
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ namespace SqlSugar
|
|||||||
IDbFirst SettingPropertyDescriptionTemplate(Func<string, string> func);
|
IDbFirst SettingPropertyDescriptionTemplate(Func<string, string> func);
|
||||||
IDbFirst SettingConstructorTemplate(Func<string, string> func);
|
IDbFirst SettingConstructorTemplate(Func<string, string> func);
|
||||||
IDbFirst SettingNamespaceTemplate(Func<string, string> func);
|
IDbFirst SettingNamespaceTemplate(Func<string, string> func);
|
||||||
DbRazor SettingTemplate(string Path);
|
RazorFirst UseRazorAnalysis(string razorClassString, string classNamespace = "Models");
|
||||||
IDbFirst IsCreateAttribute(bool isCreateAttribute = true);
|
IDbFirst IsCreateAttribute(bool isCreateAttribute = true);
|
||||||
IDbFirst IsCreateDefaultValue(bool isCreateDefaultValue=true);
|
IDbFirst IsCreateDefaultValue(bool isCreateDefaultValue=true);
|
||||||
IDbFirst Where(params string[] objectNames);
|
IDbFirst Where(params string[] objectNames);
|
||||||
|
@ -121,6 +121,7 @@
|
|||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhere.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubWhere.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\SubResolve.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\SubResolve.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\SubTools.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\SubTools.cs" />
|
||||||
|
<Compile Include="ExternalServiceInterface\IRazorService.cs" />
|
||||||
<Compile Include="Infrastructure\DependencyManagement.cs" />
|
<Compile Include="Infrastructure\DependencyManagement.cs" />
|
||||||
<Compile Include="ExternalServiceInterface\ISerializeService.cs" />
|
<Compile Include="ExternalServiceInterface\ISerializeService.cs" />
|
||||||
<Compile Include="Entities\DefaultServices.cs" />
|
<Compile Include="Entities\DefaultServices.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user