MySql.Data.Entity.FunctionGenerator.GenerateSQL C# (CSharp) Method

GenerateSQL() public method

public GenerateSQL ( System.Data.Common.CommandTrees.DbCommandTree commandTree ) : string
commandTree System.Data.Common.CommandTrees.DbCommandTree
return string
        public override string GenerateSQL(DbCommandTree commandTree)
        {
            DbFunctionCommandTree tree = (commandTree as DbFunctionCommandTree);
            EdmFunction function = tree.EdmFunction;
            CommandType = CommandType.StoredProcedure;

            string cmdText = (string)function.MetadataProperties["CommandTextAttribute"].Value;
            if (String.IsNullOrEmpty(cmdText))
            {
                string schema = (string)function.MetadataProperties["Schema"].Value;
                if (String.IsNullOrEmpty(schema))
                    schema = function.NamespaceName;

                string functionName = (string)function.MetadataProperties["StoreFunctionNameAttribute"].Value;
                if (String.IsNullOrEmpty(functionName))
                    functionName = function.Name;

                return String.Format("`{0}`", functionName);
            }
            else
            {
                CommandType = CommandType.Text;
                return cmdText;
            }
        }
    }

Usage Example

Example #1
0
        protected virtual MigrationStatement Generate(HistoryOperation op)
        {
            if (op == null)
            {
                return(null);
            }

            MigrationStatement stmt = new MigrationStatement();

            var          cmdStr    = "";
            SqlGenerator generator = new SelectGenerator();

            foreach (var commandTree in op.CommandTrees)
            {
                switch (commandTree.CommandTreeKind)
                {
                case DbCommandTreeKind.Insert:
                    generator = new InsertGenerator();
                    break;

                case DbCommandTreeKind.Delete:
                    generator = new DeleteGenerator();
                    break;

                case DbCommandTreeKind.Update:
                    generator = new UpdateGenerator();
                    break;

                case DbCommandTreeKind.Query:
                    generator = new SelectGenerator();
                    break;

                case DbCommandTreeKind.Function:
                    generator = new FunctionGenerator();
                    break;

                default:
                    throw new NotImplementedException(commandTree.CommandTreeKind.ToString());
                }
                cmdStr = generator.GenerateSQL(commandTree);

                ReplaceParemeters(ref cmdStr, generator.Parameters);
                stmt.Sql += cmdStr.Replace("dbo", "") + ";";
            }
            return(stmt);
        }
All Usage Examples Of MySql.Data.Entity.FunctionGenerator::GenerateSQL
FunctionGenerator