Exemplo n.º 1
0
        public StringBuilder BuildSelectAllByForeignKeyInterface(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            foreach (Key k in entity.GetForeignKeys())
            {
                res.AppendLine($"IEnumerable<{entity.ClrName}> GetAllBy{k.ClrName}({k.GetClrType()} {k.ClrName});");
            }
            return res;
        }
Exemplo n.º 2
0
 public StringBuilder BuildUpdatePublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"public void Update({entity.ClrName} entity){{");
     res.AppendLine("IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.Update);");
     res.AppendLine("BuildUpdateQuery(ref statement, entity);");
     res.AppendLine("Execute(statement);");
     res.AppendLine("}");
     return res;
 }
Exemplo n.º 3
0
        public StringBuilder BuildCountAllPrivate(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            res.AppendLine($"private void BuildCountQuery(ref IStatementBuilder sb){{");
            res.AppendLine($"sb.Append(\"select count(1) from {entity.Name}\");");
            res.AppendLine("}");

            return res;
        }
Exemplo n.º 4
0
 public StringBuilder BuildDeleteAllPublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"public void DeleteAll(){{");
     res.AppendLine($"IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.Delete);");
     res.AppendLine($"BuildDeleteAllQuery(ref statement);");
     res.AppendLine($"Execute(statement);");
     res.AppendLine("}");
     return res;
 }
Exemplo n.º 5
0
        public StringBuilder BuildDeleteByForeignKeyInterface(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            foreach (Key k in entity.GetForeignKeys())
            {
                res.AppendLine($"void DeleteAllBy{k.ClrName}({k.GetClrType()} {k.Name});");
            }
            return res;
        }
Exemplo n.º 6
0
 public StringBuilder BuildCountAllPublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"public int Count(){{");
     res.AppendLine($"IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.SelectSingleRow);");
     res.AppendLine($"BuildCountQuery(ref statement);");
     res.AppendLine($"IResult query = Execute(statement);");
     res.AppendLine($"int res = query.ValueAsInt();");
     res.AppendLine($"return res;");
     res.AppendLine("}");
     return res;
 }
Exemplo n.º 7
0
        public StringBuilder BuildDeleteAllPrivate(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            res.AppendLine("private void BuildDeleteAllQuery(ref IStatementBuilder res)");

            res.AppendLine("{");
            res.AppendLine($"res.Append(\"DELETE FROM [dbo].[{entity.Name}] \");");

            res.AppendLine("}");

            return res;
        }
Exemplo n.º 8
0
        public StringBuilder BuildDeleteByForeignKeyPrivate(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            foreach (Key fk in entity.GetForeignKeys())
            {
                res.AppendLine($"private void BuildDeleteAllBy{fk.ClrName}Query(ref IStatementBuilder sb,{fk.GetClrType()} {fk.ClrName}){{");
                res.AppendLine($"sb.Append(\"delete from {entity.Name} where {fk.Name} = @{fk.Name}\");");
                res.AppendLine($"sb.AddParameter(\"{fk.Name}\", {fk.ClrName},DbType.{fk.GetDbType()});");
                res.AppendLine("}");
            }

            return res;
        }
Exemplo n.º 9
0
        public StringBuilder BuildDeleteByForeignKeyPublic(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            foreach (Key fk in entity.GetForeignKeys())
            {
                res.AppendLine($"public void DeleteAllBy{fk.ClrName}({fk.GetClrType()} {fk.ClrName}){{");
                res.AppendLine("IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.Delete);");
                res.AppendLine($"BuildDeleteAllBy{fk.ClrName}Query(ref statement, {fk.ClrName});");
                res.AppendLine("Execute(statement);");
                res.AppendLine("}");
            }
            return res;
        }
Exemplo n.º 10
0
 public StringBuilder BuildInsertPublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"public {entity.ClrName} Insert({entity.ClrName} item){{");
     res.AppendLine("IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.Insert);");
     res.AppendLine($"BuildInsert{entity.ClrName}Query(ref statement, item);");
     res.AppendLine("IResult query = Execute(statement);");
     if (entity.Keys.Any(pK => pK.IsIdentity))
     {
         res.AppendLine($"item.{entity.Keys.Single(pK => pK.IsIdentity).ClrName}=query.ValueAsInt();");
     }
     res.AppendLine("return item;");
     res.AppendLine("}");
     return res;
 }
Exemplo n.º 11
0
        public StringBuilder BuildUpdatePrivate(DataStructure entity)
        {
            StringBuilder sb = new StringBuilder();
            var primaryKeys = entity.Keys.Where(pK => pK.IsPrimary);
            var otherKeys = entity.Keys.Where(pK => !pK.IsPrimary);
            sb.AppendLine($"private void BuildUpdateQuery(ref IStatementBuilder sb, {entity.ClrName} pItem)");
            sb.AppendLine("{");
            sb.AppendLine($"sb.Append(\"UPDATE [dbo].[{entity.Name}] \");");
            sb.AppendLine("sb.Append(\"SET\");");
            foreach (var k in otherKeys)
            {
                if (k.Name == otherKeys.First().Name)
                {
                    sb.AppendLine($"sb.Append(\"[{ k.Name}] = @{ k.Name} \");");
                }
                else
                {
                    sb.AppendLine($"sb.Append(\",[{ k.Name}] = @{ k.Name} \");");
                }
            }

            foreach (var k in primaryKeys)
            {
                if (k.Name == primaryKeys.First().Name)
                {
                    sb.AppendLine($"sb.Append(\"WHERE [{ k.Name}] = @{ k.Name} \");");
                }
                else
                {
                    sb.AppendLine($"sb.Append(\"AND [{ k.Name}] = @{ k.Name} \");");
                }
            }

            foreach (var k in otherKeys)
            {
                sb.AppendLine($"sb.AddParameter(\"{k.Name}\", pItem.{k.ClrName},DbType.{k.GetDbType()});");

            }

            foreach (var k in primaryKeys)
            {
                sb.AppendLine($"sb.AddParameter(\"{ k.Name}\", pItem.{ k.ClrName},DbType.{k.GetDbType()});");

            }

            sb.AppendLine("}");
            return sb;
        }
Exemplo n.º 12
0
 public virtual void GenerateEntity(DataStructure structure)
 {
     try
     {
         string template = ReadTemplate("EntityTemplate.txt");
         string entityNamespace = _parameterReaderService.Get<string>("namespace", "entity");
         string filePath = Path.Combine(_parameterReaderService.Get<string>("output", "baseDirectory"), _parameterReaderService.Get<string>("output", "entityDirectory"));
         template = template.Replace("#NAMESPACE#", entityNamespace);
         template = template.Replace("#ENTITY#", structure.ClrName);
         template = template.Replace("#KEYS#", string.Join(Environment.NewLine + Environment.NewLine, structure.Keys.Select(GenerateKey)));
         WriteFile(filePath, $"{structure.ClrName}.generated.cs", template);
     }
     catch (Exception ex)
     {
         _logger.Exception(ex);
     }
 }
Exemplo n.º 13
0
        public StringBuilder BuildInsertPrivate(DataStructure entity)
        {
            StringBuilder sb = new StringBuilder();
            var keysToInsert = entity.Keys.Where(pK => !pK.IsIdentity);
            sb.AppendLine($"private void BuildInsert{entity.ClrName}Query(ref IStatementBuilder sb, {entity.ClrName} pItem)");
            sb.AppendLine("{");
            sb.AppendLine($"sb.Append(\"INSERT INTO [dbo].[{keysToInsert.Select(pk => pk.Name).Aggregate((pA, pB) => pA + "], [" + pB)}] ([{ entity.Name}])\"); ");
            sb.AppendLine("sb.Append(\"VALUES( \");");
            foreach (var k in keysToInsert)
            {
                string sep;
                if (keysToInsert.Last().Name == k.Name)
                {
                    sep = ");";
                }
                else
                {
                    sep = ",";
                }
                sb.AppendLine($"sb.Append(\"@{k.Name}{sep}\");");
                sb.AppendLine();
            }

            if (entity.Keys.Any(pK => pK.IsIdentity))
            {
                sb.AppendLine("sb.Append(\"SELECT @@IDENTITY;\");");
            }

            foreach (var k in keysToInsert)
            {
                sb.AppendLine($"sb.AddParameter(\"{k.Name}\", pItem.{k.ClrName},DbType.{k.GetDbType()});");
                sb.AppendLine();
            }

            sb.AppendLine("}");
            sb.AppendLine();

            return sb;
        }
Exemplo n.º 14
0
 public StringBuilder BuildDeleteAllInterface(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"void DeleteAll();");
     return res;
 }
Exemplo n.º 15
0
 public StringBuilder BuildInsertInterface(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"{entity.ClrName} Insert({entity.ClrName} {entity.Name});");
     return res;
 }
Exemplo n.º 16
0
 public StringBuilder BuildSelectAllWithPaginationPublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     if (entity.GetPrimaryKeys().Any())
     {
         res.AppendLine($"public IPagedEnumerable<{entity.ClrName}> GetAllPaged(int pageSize ,int page){{");
         res.AppendLine($"IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.SelectMultipleRows);");
         res.AppendLine($"BuildGetAllPagedQuery(ref statement,pageSize,page);");
         res.AppendLine($"IResult query = Execute(statement);");
         res.AppendLine($"IPagedEnumerable<{entity.ClrName}> res = new PagedEnumerable<{entity.ClrName}>(query.ToList<{entity.ClrName}>(),page,pageSize,0);");
         res.AppendLine($"return res;");
         res.AppendLine("}");
     }
     return res;
 }
Exemplo n.º 17
0
 public StringBuilder BuildDeleteByIdInterface(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     if (entity.GetPrimaryKeys().Any())
     {
         string parameters = entity.GetPrimaryKeys().Select(pk => $"{pk.GetClrType()} {pk.ClrName}").Aggregate((a, b) => a + ", " + b);
         res.AppendLine($"void Delete({parameters});");
     }
     return res;
 }
Exemplo n.º 18
0
 public StringBuilder BuildCountAllInterface(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"int Count();");
     return res;
 }
Exemplo n.º 19
0
        public StringBuilder BuildSelectSingleByForeignKeyPublic(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            foreach (Key fk in entity.GetForeignKeys())
            {
                res.AppendLine($"public {entity.ClrName} GetBy{fk.ClrName}({fk.GetClrType()} {fk.ClrName}){{");
                res.AppendLine($"IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.SelectSingleRow);");
                res.AppendLine($"BuildGetBy{fk.ClrName}Query(ref statement, {fk.ClrName});");
                res.AppendLine($"IResult query = Execute(statement);");
                res.AppendLine($"{entity.ClrName} res = query.SingleOrDefault<{entity.ClrName}>();");
                res.AppendLine($"return res;");
                res.AppendLine("}");
            }
            return res;
        }
Exemplo n.º 20
0
 public StringBuilder BuildSelectSingleByIdPublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     if (entity.GetPrimaryKeys().Any())
     {
         string protoParameters = entity.GetPrimaryKeys().Select(pk => $"{pk.GetClrType()} {pk.ClrName}").Aggregate((a, b) => a + ", " + b);
         res.AppendLine($"public {entity.ClrName} Get({protoParameters}){{");
         res.AppendLine($"IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.SelectSingleRow);");
         string parameters = entity.GetPrimaryKeys().Select(pk => $"{pk.ClrName}").Aggregate((a, b) => a + ", " + b);
         res.AppendLine($"BuildGetQuery(ref statement, {parameters});");
         res.AppendLine($"IResult query = Execute(statement);");
         res.AppendLine($"{entity.ClrName} res = query.SingleOrDefault<{entity.ClrName}>();");
         res.AppendLine($"return res;");
         res.AppendLine("}");
     }
     return res;
 }
Exemplo n.º 21
0
        public StringBuilder BuildSelectSingleByIdPrivate(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();
            if (entity.GetPrimaryKeys().Any())
            {
                string protoParameters = entity.GetPrimaryKeys().Select(pk => $"{pk.GetClrType()} {pk.ClrName}").Aggregate((a, b) => a + ", " + b);
                string parameters = entity.GetPrimaryKeys().Select(pk => $"{pk.ClrName}").Aggregate((a, b) => a + ", " + b);
                res.AppendLine($"private void BuildGetQuery(ref IStatementBuilder sb,{protoParameters}){{");
                res.AppendLine($"sb.Append(\"select top 1 * from {entity.Name} where \");");

                foreach (var k in entity.GetPrimaryKeys())
                {
                    if (k.Name == entity.GetPrimaryKeys().First().Name)
                    {
                        res.AppendLine($"sb.Append(\"WHERE [{k.Name}] = @{k.Name} \");");
                    }
                    else
                    {
                        res.AppendLine($"sb.Append(\"AND [{k.Name}] = @{k.Name} \");");
                    }
                }

                foreach (var k in entity.GetPrimaryKeys())
                {
                    res.AppendLine($"sb.AddParameter(\"{k.Name}\", {k.ClrName},DbType.{k.GetDbType()});");
                }

                res.AppendLine("}");
            }
            return res;
        }
Exemplo n.º 22
0
 public StringBuilder BuildDeleteByIdsPublic(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     if (entity.GetPrimaryKeys().Any())
     {
         string parameter = entity.GetPrimaryKeys().Select(pk => $"IEnumerable<{pk.GetClrType()}> {pk.ClrName}").Single();
         res.AppendLine($"public void DeleteAllByIds({parameter}){{");
         res.AppendLine("IStatementBuilder statement = _statementBuilderFactory.Build(QueryType.Delete);");
         string parameters = entity.GetPrimaryKeys().Select(pk => $"{pk.ClrName}").Aggregate((a, b) => a + ", " + b);
         res.AppendLine($"BuildDeleteAllByIdsQuery(ref statement,{parameters});");
         res.AppendLine("Execute(statement);");
         res.AppendLine("}");
     }
     return res;
 }
Exemplo n.º 23
0
        public StringBuilder BuildSelectAllWithPaginationPrivate(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();

            if (entity.GetPrimaryKeys().Any())
            {
                string primaryKeys = entity.GetPrimaryKeys().Select(pk => $"{pk.Name}").Aggregate((a, b) => a + ", " + b);
                res.AppendLine($"private void BuildGetAllPagedQuery(ref IStatementBuilder sb, int pageSize ,int page){{");
                res.AppendLine($"sb.Append(\";With SQLPaging As(\");");
                res.AppendLine($"sb.Append(\"Select Top(@pageSize * @page) ROW_NUMBER() OVER(ORDER BY {primaryKeys} asc)\");");
                res.AppendLine($"sb.Append(\"as resultNum, *\");");
                res.AppendLine($"sb.Append(\"FROM {entity.Name} )\");");
                res.AppendLine($"sb.Append(\"select * from SQLPaging with (nolock) where resultNum > ((@page - 1) * @pageSize)\");");

                res.AppendLine($"sb.AddParameter(\"page\", page,DbType.Int32);");
                res.AppendLine($"sb.AddParameter(\"pageSize\",pageSize,DbType.Int32);");
                res.AppendLine("}");
            }
            return res;
        }
Exemplo n.º 24
0
        private void GenerateProviderImpl(DataStructure table)
        {
            try
            {
                string template = ReadTemplate("ProviderImplTemplate.txt");
                string entityNamespace = _parameterReaderService.Get<string>("namespace", "entity");
                string providerImplNamespace = _parameterReaderService.Get<string>("namespace", "provider", "impl");
                string providerInterfaceNamespace = _parameterReaderService.Get<string>("namespace", "provider", "interface");
                string baseClassNamespace = _parameterReaderService.Get<string>("provider", "baseClass", "namespace");
                string baseClassName = _parameterReaderService.Get<string>("provider", "baseClass", "name");

                string filePath = Path.Combine(_parameterReaderService.Get<string>("output", "baseDirectory"), _parameterReaderService.Get<string>("output", "providerDirectory", "impl"));
                template = template.Replace("#NAMESPACE#", providerImplNamespace);
                template = template.Replace("#INTERFACE-NAMESPACE#", providerInterfaceNamespace);
                template = template.Replace("#ENTITY-NAMESPACE#", entityNamespace);
                template = template.Replace("#ENTITY#", table.Name);
                template = template.Replace("#BASE-CLASS-NAMESPACE#", baseClassNamespace);
                template = template.Replace("#BASE-CLASS#", baseClassName);

                StringBuilder publicMethods = new StringBuilder();
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectSingleByIdPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildCountAllPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByForeignKeyPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByForeignKeyWithPaginationPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByIdsPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByIdsWithPaginationPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectAllPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectAllWithPaginationPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildSelectSingleByForeignKeyPublic(table).ToString());
                publicMethods.AppendLine(_selectQueryGenerator.BuildAnyPublic(table).ToString());

                if (table.Type == Entity.DataStructureType.Table)
                {
                    publicMethods.AppendLine(_insertQueryGenerator.BuildInsertPublic(table).ToString());
                    publicMethods.AppendLine(_updateQueryGenerator.BuildUpdatePublic(table).ToString());
                    publicMethods.AppendLine(_deleteQueryGenerator.BuildDeleteAllPublic(table).ToString());
                    publicMethods.AppendLine(_deleteQueryGenerator.BuildDeleteByIdPublic(table).ToString());
                    publicMethods.AppendLine(_deleteQueryGenerator.BuildDeleteByForeignKeyPublic(table).ToString());
                    publicMethods.AppendLine(_deleteQueryGenerator.BuildDeleteByIdsPublic(table).ToString());
                }
                template = template.Replace("#PUBLIC-METHODS#", publicMethods.ToString());

                StringBuilder privateMethods = new StringBuilder();
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectSingleByIdPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildCountAllPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByForeignKeyPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByForeignKeyWithPaginationPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByIdsPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectAllByIdsWithPaginationPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectAllPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectAllWithPaginationPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildSelectSingleByForeignKeyPrivate(table).ToString());
                privateMethods.AppendLine(_selectQueryGenerator.BuildAnyPrivate(table).ToString());

                if (table.Type == Entity.DataStructureType.Table)
                {
                    privateMethods.AppendLine(_insertQueryGenerator.BuildInsertPrivate(table).ToString());
                    privateMethods.AppendLine(_updateQueryGenerator.BuildUpdatePrivate(table).ToString());
                    privateMethods.AppendLine(_deleteQueryGenerator.BuildDeleteAllPrivate(table).ToString());
                    privateMethods.AppendLine(_deleteQueryGenerator.BuildDeleteByIdPrivate(table).ToString());
                    privateMethods.AppendLine(_deleteQueryGenerator.BuildDeleteByForeignKeyPrivate(table).ToString());
                    privateMethods.AppendLine(_deleteQueryGenerator.BuildDeleteByIdsPrivate(table).ToString());
                }
                template = template.Replace("#PRIVATE-METHODS#", privateMethods.ToString());

                WriteFile(filePath, $"{table.Name}Provider.generated.cs", template);
            }
            catch (Exception ex)
            {
                _logger.Exception(ex);
            }
        }
Exemplo n.º 25
0
        private void GenerateProviderInterface(DataStructure table)
        {
            try
            {
                string template = ReadTemplate("ProviderInterfaceTemplate.txt");
                string entityNamespace = _parameterReaderService.Get<string>("namespace", "entity");
                string providerNamespace = _parameterReaderService.Get<string>("namespace", "provider", "interface");
                string filePath = Path.Combine(_parameterReaderService.Get<string>("output", "baseDirectory"), _parameterReaderService.Get<string>("output", "providerDirectory", "interface"));
                template = template.Replace("#NAMESPACE#", providerNamespace);
                template = template.Replace("#ENTITY-NAMESPACE#", entityNamespace);
                template = template.Replace("#ENTITY#", table.Name);
                StringBuilder methods = new StringBuilder();

                methods.AppendLine(_selectQueryGenerator.BuildSelectSingleByIdInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildCountAllInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectAllByForeignKeyInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectAllByForeignKeyWithPaginationInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectAllByIdsInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectAllByIdsWithPaginationInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectAllInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectAllWithPaginationInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildSelectSingleByForeignKeyInterface(table).ToString());
                methods.AppendLine(_selectQueryGenerator.BuildAnyInterface(table).ToString());

                if (table.Type == Entity.DataStructureType.Table)
                {
                    methods.AppendLine(_insertQueryGenerator.BuildInsertInterface(table).ToString());
                    methods.AppendLine(_updateQueryGenerator.BuildUpdateInterface(table).ToString());
                    methods.AppendLine(_deleteQueryGenerator.BuildDeleteAllInterface(table).ToString());
                    methods.AppendLine(_deleteQueryGenerator.BuildDeleteByIdInterface(table).ToString());
                    methods.AppendLine(_deleteQueryGenerator.BuildDeleteByForeignKeyInterface(table).ToString());
                    methods.AppendLine(_deleteQueryGenerator.BuildDeleteByIdsInterface(table).ToString());
                }
                template = template.Replace("#METHODS#", methods.ToString());
                WriteFile(filePath, $"I{table.Name}Provider.generated.cs", template);
            }
            catch (Exception ex)
            {
                _logger.Exception(ex);
            }
        }
Exemplo n.º 26
0
 public StringBuilder BuildUpdateInterface(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     res.AppendLine($"void Update({entity.ClrName} {entity.ClrName});");
     return res;
 }
Exemplo n.º 27
0
 public void GenerateProvider(DataStructure table)
 {
     GenerateProviderInterface(table);
     GenerateProviderImpl(table);
 }
Exemplo n.º 28
0
 public StringBuilder BuildDeleteByIdsInterface(DataStructure entity)
 {
     StringBuilder res;
     if (entity.GetPrimaryKeys().Count() == 1)
     {
         string parameter = entity.GetPrimaryKeys().Select(pk => $"IEnumerable<{pk.GetClrType()}> {pk.ClrName}").Single();
         res = new StringBuilder($"void DeleteAllByIds({parameter});");
     }
     else {
         res = new StringBuilder();
     }
     return res;
 }
Exemplo n.º 29
0
        public StringBuilder BuildDeleteByIdsPrivate(DataStructure entity)
        {
            StringBuilder res = new StringBuilder();
            if (entity.GetPrimaryKeys().Any())
            {
                string parameter = entity.GetPrimaryKeys().Select(pk => $"IEnumerable<{pk.GetClrType()}> {pk.ClrName}").Single();
                res.AppendLine($"private void BuildDeleteAllByIdsQuery(ref IStatementBuilder sb,{parameter}){{");
                res.AppendLine($"sb.Append(\"delete from {entity.Name} where \");");

                foreach (var k in entity.GetPrimaryKeys())
                {
                    if (k.Name == entity.GetPrimaryKeys().First().Name)
                    {
                        res.AppendLine($"sb.Append(\"WHERE [{k.Name}] = @{k.Name} \");");
                    }
                    else
                    {
                        res.AppendLine($"sb.Append(\"AND [{k.Name}] = @{k.Name} \");");
                    }
                }

                foreach (var k in entity.GetPrimaryKeys())
                {
                    res.AppendLine($"sb.AddParameter(\"{k.Name}\", {k.ClrName},DbType.{k.GetDbType()});");
                }
                res.AppendLine("}");
            }
            return res;
        }
Exemplo n.º 30
0
 public StringBuilder BuildSelectAllWithPaginationInterface(DataStructure entity)
 {
     StringBuilder res = new StringBuilder();
     if (entity.GetPrimaryKeys().Any())
     {
         res.AppendLine($"IPagedEnumerable<{entity.ClrName}> GetAllPaged(int pageSize ,int page);");
     }
     return res;
 }