Esempio n. 1
0
        public static void GenerateInsertMethod(CodeStringBuilder code, TableInfo tableInfo)
        {
            String            entityTypeName  = tableInfo.ClassName;
            String            target          = String.Format("[{0}].[{1}]", tableInfo.Schema, tableInfo.Name);
            String            methodName      = String.Format("Insert{0}", entityTypeName);
            List <ColumnInfo> editableColumns = tableInfo.GetEditableColumns();
            List <ColumnInfo> computedColumns = tableInfo.GetComputedColumns();
            List <ColumnInfo> identityColumns = tableInfo.GetIdentityColumns();
            List <ColumnInfo> key             = tableInfo.GetKey();

            List <ColumnInfo> readBackColumns = new List <ColumnInfo>();

            readBackColumns.AddRange(identityColumns);
            readBackColumns.AddRange(computedColumns);

            if (editableColumns.Count == 0)
            {
                return;
            }

            // generate sql script
            StringBuilder script = new StringBuilder();

            SQLTextGenerator.GenerateInsertStatement(script, target, editableColumns, readBackColumns);

            // generate code for script
            CSharpTextGenerator.GenerateInsertMethod(code, methodName, entityTypeName, script.ToString(), editableColumns, readBackColumns);
        }
Esempio n. 2
0
        public static void GenerateUpdateMethod(CodeStringBuilder code, TableInfo tableInfo)
        {
            String            entityTypeName  = tableInfo.ClassName;
            String            target          = String.Format("[{0}].[{1}]", tableInfo.Schema, tableInfo.Name);
            String            methodName      = String.Format("Update{0}", entityTypeName);
            List <ColumnInfo> editableColumns = tableInfo.GetEditableColumns();
            List <ColumnInfo> computedColumns = tableInfo.GetComputedColumns();
            List <ColumnInfo> key             = tableInfo.GetKey();

            if (editableColumns.Count == 0)
            {
                return;
            }

            if (key.SequenceEqual(editableColumns))
            {
                return;
            }

            // generate sql script
            StringBuilder script = new StringBuilder();

            SQLTextGenerator.GenerateUpdateStatement(script, target, key, editableColumns, computedColumns);

            // generate code for script
            CSharpTextGenerator.GenerateUpdateMethod(code, methodName, entityTypeName, script.ToString(), key, editableColumns, computedColumns);
        }
Esempio n. 3
0
        public static void GenerateSelectPagedMethod(CodeStringBuilder code, TableInfo tableInfo, String mappingMethodName)
        {
            String            entityTypeName = tableInfo.ClassName;
            String            target         = String.Format("[{0}].[{1}]", tableInfo.Schema, tableInfo.Name);
            List <ColumnInfo> key            = tableInfo.GetKey();

            StringBuilder methodName = new StringBuilder();

            methodName.Append("Select");
            methodName.Append(entityTypeName);
            methodName.Append("Paged");

            if (key == null || key.Count == 0)
            {
                return;
            }

            // generate sql script
            StringBuilder script = new StringBuilder();

            SQLTextGenerator.GenerateSelectStatementPaged(script, target, tableInfo.Columns, "@__FirstIndex", "@__LastIndex", key, null);

            // generate code for script
            CSharpTextGenerator.GenerateSelectPagedMethod(code, methodName.ToString(), entityTypeName, mappingMethodName, script.ToString(), key);
        }
Esempio n. 4
0
        public static void GenerateSelectMethod(CodeStringBuilder code, TableInfo tableInfo, List <ColumnInfo> key, bool singleResult, String mappingMethodName)
        {
            String entityTypeName = tableInfo.ClassName;
            String target         = String.Format("[{0}].[{1}]", tableInfo.Schema, tableInfo.Name);

            StringBuilder methodName = new StringBuilder();

            methodName.Append("Select");
            methodName.Append(entityTypeName);
            if (key != null && key.Count > 0)
            {
                methodName.Append("By");
                foreach (var k in key)
                {
                    methodName.Append(k.PropertyName);
                }
            }

            // generate sql script
            StringBuilder script = new StringBuilder();

            SQLTextGenerator.GenerateSelectStatement(script, target, tableInfo.Columns, key);

            // generate code for script
            CSharpTextGenerator.GenerateSelectMethod(code, methodName.ToString(), entityTypeName, script.ToString(), key, singleResult, mappingMethodName);
        }
Esempio n. 5
0
        public static void GenerateDeleteMethod(CodeStringBuilder code, TableInfo tableInfo, List <ColumnInfo> key)
        {
            if (key == null || key.Count == 0)
            {
                return;
            }

            String entityTypeName = tableInfo.ClassName;
            String target         = String.Format("[{0}].[{1}]", tableInfo.Schema, tableInfo.Name);

            StringBuilder methodName = new StringBuilder();

            methodName.Append("Delete");
            methodName.Append(entityTypeName);
            methodName.Append("By");
            foreach (var k in key)
            {
                methodName.Append(k.PropertyName);
            }

            // generate sql script
            StringBuilder script = new StringBuilder();

            SQLTextGenerator.GenerateDeleteStatement(script, target, key);

            // generate code for script
            CSharpTextGenerator.GenerateDeleteMethod(code, methodName.ToString(), script.ToString(), key);
        }
Esempio n. 6
0
        public static void GenerateSelectCountMethod(CodeStringBuilder code, TableInfo tableInfo)
        {
            String entityTypeName = tableInfo.ClassName;
            String target         = String.Format("[{0}].[{1}]", tableInfo.Schema, tableInfo.Name);

            StringBuilder methodName = new StringBuilder();

            methodName.Append("Select");
            methodName.Append(entityTypeName);
            methodName.Append("Count");

            // generate sql script
            StringBuilder script = new StringBuilder();

            SQLTextGenerator.GenerateSelectStatementCount(script, target, null);

            // generate code for script
            CSharpTextGenerator.GenerateSelectCountMethod(code, methodName.ToString(), script.ToString());
        }