DBSchema.tt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <#@ template debug="true" hostspecific="true" language="C#" #>
  2. <#@ assembly name="System.Core" #>
  3. <#@ assembly name="System.Data" #>
  4. <#@ assembly name="$(SolutionDir)\Lib\SCADA.CommonLib.dll" #>
  5. <#@ assembly name="$(SolutionDir)\Lib\System.Data.SQLite.dll" #>
  6. <#@ import namespace="System.Linq" #>
  7. <#@ import namespace="System.Text" #>
  8. <#@ import namespace="System.Collections.Generic" #>
  9. <#@ import namespace="System.Data" #>
  10. <#@ import namespace="SCADA.CommonLib.Data"#>
  11. <#@ import namespace="SCADA.CommonLib.Data.DIL"#>
  12. <#@ import namespace="SCADA.CommonLib.Data.DIL.MSSql"#>
  13. <#@ import namespace="SCADA.CommonLib.Data.DIL.MySql"#>
  14. <#@ import namespace="SCADA.CommonLib.Data.DIL.Sqlite"#>
  15. <#@ import namespace="SCADA.CommonLib.Data.DIL.Oracle"#>
  16. <#@ import namespace="SCADA.CommonLib.Data.DIL.NpgSql"#>
  17. <#@ import namespace="SCADA.CommonLib.Data.DIL.Sqlite"#>
  18. <#@ import namespace="Microsoft.VisualStudio.TextTemplating"#>
  19. <#@ output extension=".cs" #>
  20. <#
  21. string ttpath = this.Host.TemplateFile;
  22. string projectPath=Host.ResolveAssemblyReference("$(SolutionDir)");
  23. string outPath=Host.ResolveAssemblyReference("$(TargetDir)");
  24. // IDB db=new SQLDB("127.0.0.1,1433","EICP","sa","123456");
  25. // IDB db=new OracleDB("127.0.0.1:1521","EICP","sa","123456");
  26. // IDB db=new MySQLDB("127.0.0.1:3306","EICP","sa","123456");
  27. string dataPath=@$"{projectPath}\SCADA_DAQ\bin\Debug\net47\Data";
  28. IDB db=new SQLiteDB(dataPath,"Platform.db");
  29. #>
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Linq.Expressions;
  33. using SCADA.CommonLib;
  34. using SCADA.CommonLib.Data;
  35. using SCADA.CommonLib.Data.DIL;
  36. <#if(db is SQLDB)
  37. {
  38. WriteLine("using System.Data.SqlClient;");
  39. WriteLine("using SCADA.CommonLib.Data.DIL.MSSql;");
  40. }
  41. else if(db is MySQLDB)
  42. {
  43. WriteLine("using SCADA.CommonLib.Data.DIL.MySql;");
  44. }
  45. else if(db is SQLiteDB)
  46. {
  47. WriteLine("using SCADA.CommonLib.Data.DIL.Sqlite;");
  48. }
  49. else if(db is OracleDB)
  50. {
  51. WriteLine("using SCADA.CommonLib.Data.DIL.Oracle;");
  52. }
  53. else if(db is NpgSQLDB)
  54. {
  55. WriteLine("using SCADA.CommonLib.Data.DIL.NpgSql;");
  56. }
  57. #>
  58. namespace DBSchema
  59. {
  60. <#= db.GetProduceDefine() #>
  61. }
  62. namespace DBNames
  63. {
  64. <#=db.GetTableColumnsDefine() #>
  65. <#=db.GetViewColumnsDefine() #>
  66. <#=db.GetProduceParametersDefine() #>
  67. }
  68. namespace DBModel
  69. {
  70. <#= db.GetDBModel() #>
  71. }
  72. namespace DIL
  73. {
  74. <#if(db is SQLDB)
  75. {
  76. WriteLine(" public class DILDB:SQLDB");
  77. }
  78. else if(db is MySQLDB)
  79. {
  80. WriteLine(" public class DILDB:MySQLDB");
  81. }
  82. else if(db is SQLiteDB)
  83. {
  84. WriteLine(" public class DILDB:SQLiteDB");
  85. }
  86. else if(db is OracleDB)
  87. {
  88. WriteLine(" public class DILDB:OracleDB");
  89. }
  90. else if(db is NpgSQLDB)
  91. {
  92. WriteLine(" public class DILDB:NpgSQLDB");
  93. }
  94. #>
  95. {
  96. <#= db.GetDeclare() #>
  97. }
  98. }