當前位置: 首頁>>代碼示例>>C#>>正文


C# ModelRoot.GetSQLDefaultDate方法代碼示例

本文整理匯總了C#中nHydrate.Generator.Models.ModelRoot.GetSQLDefaultDate方法的典型用法代碼示例。如果您正苦於以下問題:C# ModelRoot.GetSQLDefaultDate方法的具體用法?C# ModelRoot.GetSQLDefaultDate怎麽用?C# ModelRoot.GetSQLDefaultDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nHydrate.Generator.Models.ModelRoot的用法示例。


在下文中一共展示了ModelRoot.GetSQLDefaultDate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetBody

            public static string GetBody(Table table, ModelRoot model)
            {
                var sb = new StringBuilder();

                if (table.AllowModifiedAudit)
                {
                    sb.AppendLine("IF (@" + model.Database.ModifiedDateColumnName + " IS NULL)");
                    sb.AppendLine("SET @" + model.Database.ModifiedDateColumnName + " = " + model.GetSQLDefaultDate() + ";");
                    sb.AppendLine();
                }

                sb.AppendLine("SET NOCOUNT ON;");

                if (!table.Immutable)
                {
                    var tableList = table.GetTableHierarchy();
                    foreach (var t in tableList)
                    {
                        //If there is nothing to set then do not do anything
                        var setStatment = BuildSetStatement(t, model);
                        if (!string.IsNullOrEmpty(setStatment))
                        {
                            sb.AppendLine("UPDATE ");
                            sb.AppendLine("\t[" + t.GetSQLSchema() + "].[" + t.DatabaseName + "] ");
                            sb.AppendLine("SET");
                            sb.AppendLine(setStatment);
                            sb.AppendLine("WHERE");
                            sb.AppendLine("\t" + BuildUpdateWhereStatement(t, model, ((table.GetAbsoluteBaseTable() == t) && table.AllowTimestamp)));
                            sb.AppendLine();
                            sb.AppendLine("if (@@RowCount = 0) return;");
                            sb.AppendLine();
                        }
                    }
                }

                sb.AppendLine("SELECT");
                sb.Append(Globals.BuildSelectList(table, model, true));
                sb.AppendLine("FROM ");
                sb.AppendLine(table.GetFullHierarchyTableJoin());
                sb.AppendLine("WHERE");
				sb.AppendLine("\t" + BuildSelectWhereStatement(table, model));
                return sb.ToString();
            }
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:43,代碼來源:SQLGeneratedBodyHelper.cs

示例2: AppendModifiedAudit

 private static void AppendModifiedAudit(ModelRoot model, Table table, StringBuilder sb)
 {
     if (table.AllowModifiedAudit)
     {
         var dateTimeString = (model.SQLServerType == nHydrate.Generator.Common.GeneratorFramework.SQLServerTypeConstants.SQL2005) ? "[DateTime]" : "[DateTime2]";
         var defaultName = "DF__" + table.DatabaseName + "_" + model.Database.ModifiedDateColumnName;
         defaultName = defaultName.ToUpper();
         sb.AppendLine(",");
         sb.AppendLine("\t[" + model.Database.ModifiedByColumnName + "] [NVarchar] (50) NULL,");
         sb.Append("\t[" + model.Database.ModifiedDateColumnName + "] " + dateTimeString + " CONSTRAINT [" + defaultName + "] DEFAULT " + model.GetSQLDefaultDate() + " NULL");
     }
 }
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:12,代碼來源:SQLEmit.cs

示例3: GetSQLCreateAuditTable

        public static string GetSQLCreateAuditTable(ModelRoot model, Table table)
        {
            if (table.TypedTable == TypedTableConstants.EnumOnly)
                return string.Empty;

            var dateTimeString = (model.SQLServerType == nHydrate.Generator.Common.GeneratorFramework.SQLServerTypeConstants.SQL2005) ? "[DateTime]" : "[DateTime2]";
            var sb = new StringBuilder();
            var tableName = "__AUDIT__" + Globals.GetTableDatabaseName(model, table);
            sb.AppendLine("if not exists(select * from sysobjects where name = '" + tableName + "' and xtype = 'U')");
            sb.AppendLine("CREATE TABLE [" + table.GetSQLSchema() + "].[" + tableName + "] (");
            sb.AppendLine("\t[__rowid] [INT] NOT NULL IDENTITY,");
            sb.AppendLine("\t[__action] [INT] NOT NULL,");
            sb.AppendLine("\t[__insertdate] " + dateTimeString + " CONSTRAINT [DF__" + table.DatabaseName + "__AUDIT] DEFAULT " + model.GetSQLDefaultDate() + " NOT NULL,");
            if (table.AllowCreateAudit || table.AllowModifiedAudit)
                sb.AppendLine("\t[" + model.Database.ModifiedByDatabaseName + "] [NVarchar] (50) NULL,");

            var columnList = table.GetColumns().Where(x => x.Generated).ToList();
            foreach (var column in columnList)
            {
                if (!(column.DataType == System.Data.SqlDbType.Text || column.DataType == System.Data.SqlDbType.NText || column.DataType == System.Data.SqlDbType.Image))
                {
                    sb.Append("\t" + AppendColumnDefinition(column, allowDefault: false, allowIdentity: false, forceNull: true, allowFormula: false, allowComputed: false));
                    if (columnList.IndexOf(column) < columnList.Count - 1) sb.Append(",");
                    sb.AppendLine();
                }
            }
            sb.Append(")");
            sb.AppendLine();
            return sb.ToString();

        }
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:31,代碼來源:SQLEmit.cs

示例4: AppendModifiedAudit

 public static void AppendModifiedAudit(Table table, ModelRoot model, StringBuilder sb)
 {
     try
     {
         var dateTimeString = (model.SQLServerType == Common.GeneratorFramework.SQLServerTypeConstants.SQL2005) ? "[DateTime]" : "[DateTime2]";
         sb.AppendLine("--APPEND AUDIT TRAIL MODIFY FOR TABLE [" + table.DatabaseName + "]");
         sb.AppendLine("if exists(select * from sys.objects where name = '" + table.DatabaseName + "' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = '" + model.Database.ModifiedByColumnName + "' and o.name = '" + table.DatabaseName + "')");
         sb.AppendLine("ALTER TABLE [" + table.GetSQLSchema() + "].[" + table.DatabaseName + "] ADD [" + model.Database.ModifiedByColumnName + "] [NVarchar] (50) NULL");
         var dfName = "DF__" + table.DatabaseName + "_" + model.Database.ModifiedDateColumnName;
         dfName = dfName.ToUpper();
         sb.AppendLine("if exists(select * from sys.objects where name = '" + table.DatabaseName + "' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = '" + model.Database.ModifiedDateColumnName + "' and o.name = '" + table.DatabaseName + "')");
         sb.AppendLine("ALTER TABLE [" + table.GetSQLSchema() + "].[" + table.DatabaseName + "] ADD [" + model.Database.ModifiedDateColumnName + "] " + dateTimeString + " CONSTRAINT [" + dfName + "] DEFAULT " + model.GetSQLDefaultDate() + " NULL");
         sb.AppendLine("GO");
         sb.AppendLine();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:20,代碼來源:Globals.cs


注:本文中的nHydrate.Generator.Models.ModelRoot.GetSQLDefaultDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。