Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="q"></param>
 /// <param name="orderBy"></param>
 /// <param name="pageSize"></param>
 /// <param name="pageToken"></param>
 /// <param name="log"></param>
 /// <returns></returns>
 internal IDbQuery QuerySelectCommunities(
     string q, string orderBy, int?pageSize = null, string pageToken = null,
     IBdoLog log = null)
 {
     return(this.UseQuery("GetCommunityWithCode", p =>
                          DbFluent.SelectQuery(Table <DbCommunity>("community"))
                          .From(
                              DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                                   JoinCondition("Community_RegionalDirectorate")))
                          .WithFields(Tuple("SelectCommunity"))
                          .Filter(
                              q,
                              DbApiFluent.CreateFilterDefinition(
                                  DbApiFluent.CreateFilterClause("startDate", Field <DbCommunity>(p => p.CreationDate), DataOperators.GreaterOrEqual),
                                  DbApiFluent.CreateFilterClause("endDate", Field <DbCommunity>(p => p.LastModificationDate), DataOperators.LesserOrEqual),
                                  DbApiFluent.CreateFilterClause("code", Field <DbCommunity>(p => p.Code), DataOperators.Equal)),
                              log)
                          .Sort(
                              orderBy,
                              DbApiFluent.CreateSortDefinition(
                                  DbApiFluent.CreateSortClause("startDate", Field <DbCommunity>(p => p.CreationDate)),
                                  DbApiFluent.CreateSortClause("endDate", Field <DbCommunity>(p => p.LastModificationDate)),
                                  DbApiFluent.CreateSortClause("code", Field <DbCommunity>(p => p.Code))),
                              log)));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new joined table.
        /// </summary>
        /// <param name="kind">The kind to consider.</param>
        /// <param name="table1Alias">The alias of the table 1 to consider.</param>
        /// <param name="table2Alias">The alias of the table 2 to consider.</param>
        /// <returns>Returns a new From statement.</returns>
        public DbJoinedTable TableAsJoin <T, T1, T2>(
            DbQueryJoinKind kind,
            string table1Alias = null, string table2Alias = null)
        {
            var conditionScript = JoinCondition <T1, T2>(table1Alias, table2Alias);

            return(DbFluent.TableAsJoin(kind, Table <T>(), conditionScript));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="country"></param>
 /// <returns></returns>
 internal IDbQuery QueryInsertCountry(CountryDto country)
 {
     return(DbFluent.InsertQuery(Table("Country"), true)
            .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                     JoinCondition("Country_RegionalDirectorate"))));
     //.WithFields(p => Fields_InsertCountry(p, country));
 }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="community"></param>
 /// <returns></returns>
 internal IDbQuery QueryInsertCommunity(CommunityDto community)
 {
     return(DbFluent.InsertQuery(Table("Community"), true)
            .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                     JoinCondition <DbCommunity, DbRegionalDirectorate>("community", null))));
     //.WithFields(p => Fields_InsertCommunity(p, community));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete the specified employee.
        /// </summary>
        /// <param name="code">The code to consider.</param>
        /// <returns>Returns the generated query.</returns>
        internal IDbQuery DeleteEmployee6(string code)
        {
            var query = DbFluent.DeleteQuery(Table <DbEmployee>())
                        .From(
                DbFluent.TableAsJoin(
                    DbQueryJoinKind.Left,
                    Table("RegionalDirectorate").WithAlias("directorate"),
                    JoinCondition("Employee_RegionalDirectorate", null, "directorate")))
                        .Where(q => DbFluent.Eq(DbFluent.Field("code"), code));

            return(query);
        }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 internal IDbQuery QuerySelectCommunityWithCode(string code)
 {
     return(this.UseQuery("GetCommunityWithCode", p =>
                          DbFluent.SelectQuery(Table <DbCommunity>("community"))
                          .From(
                              DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                                   JoinCondition("Community_RegionalDirectorate")))
                          .WithFields(Tuple("SelectCommunity"))
                          .AddIdField(q => DbFluent.FieldAsParameter(nameof(DbCommunity.Code), q.UseParameter("code", DataValueTypes.Text))))
            .WithParameters(
                ElementFactory.CreateScalar("code", code)));
 }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <param name="isPartialUpdate"></param>
        /// <param name="employee"></param>
        /// <returns></returns>
        internal IDbQuery UpdateEmployee1(string code, bool isPartialUpdate, EmployeeDto employee)
        {
            return(this.UseQuery("UpdateEmployee1",
                                 p =>
            {
                var query = DbFluent.UpdateQuery(Table <DbEmployee>())
                            .From(
                    DbFluent.TableAsJoin(
                        DbQueryJoinKind.Left,
                        Table("RegionalDirectorate"),
                        JoinCondition("Employee_RegionalDirectorate")))
                            .WithReturnedIdFields(Field("Code", "DbEmployee"));

                query.AddField(
                    !isPartialUpdate || employee?.Code?.Length > 0,
                    q => DbFluent.FieldAsParameter(nameof(DbEmployee.Code), q.UseParameter("code", DataValueTypes.Text)));

                query.AddField(
                    !isPartialUpdate || employee?.ByteArrayField?.Length > 0,
                    q => DbFluent.FieldAsParameter(nameof(DbEmployee.ByteArrayField), q.UseParameter("byteArrayField", DataValueTypes.ByteArray)));

                query.AddField(
                    !isPartialUpdate || employee?.DateTimeField != null,
                    q => DbFluent.FieldAsParameter(nameof(DbEmployee.DoubleField), q.UseParameter("doubleField", DataValueTypes.Number)));

                query.AddField(
                    !isPartialUpdate || employee?.DoubleField != null,
                    q => DbFluent.FieldAsParameter(nameof(DbEmployee.DateTimeField), q.UseParameter("dateTimeField", DataValueTypes.Date)));

                query.AddField(
                    true,
                    q => DbFluent.FieldAsParameter(nameof(DbEmployee.LongField), q.UseParameter("longField", DataValueTypes.Long)));

                query.AddField(
                    !isPartialUpdate || employee?.RegionalDirectorateCode?.Length > 0,
                    q => DbFluent.FieldAsQuery(nameof(DbEmployee.RegionalDirectorateId),
                                               DbFluent.SelectQuery(Table("RegionalDirectorate"))
                                               .AddField(DbFluent.Field(nameof(DbRegionalDirectorate.RegionalDirectorateId)))
                                               .WithIdFields(
                                                   DbFluent.FieldAsParameter(nameof(DbRegionalDirectorate.Code), q.UseParameter("directorateCode", DataValueTypes.Text)))));

                return query;
            })
                   .WithParameters(
                       ElementFactory.CreateScalar("code", code),
                       ElementFactory.CreateScalar("byteArrayField", employee.ByteArrayField),
                       ElementFactory.CreateScalar("doubleField", employee.DoubleField),
                       ElementFactory.CreateScalar("dateTimeField", employee.DateTimeField),
                       ElementFactory.CreateScalar("directorateCode", null),
                       ElementFactory.CreateScalar("longField", employee.LongField)));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Delete the specified employee.
        /// </summary>
        /// <param name="code">The code to consider.</param>
        /// <returns>Returns the generated query.</returns>
        internal IDbQuery DeleteEmployee9(string code)
        {
            var query = DbFluent.DeleteQuery(Table <DbEmployee>())
                        .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left,
                                     Table("RegionalDirectorate").WithAlias("directorate"),
                                     JoinCondition("Employee_RegionalDirectorate")))
                        .Where(q => DbFluent.Eq(DbFluent.Field("code"), q.UseParameter("code", DataValueTypes.Text)))
                        .AddIdField(q => DbFluent.FieldAsParameter(nameof(DbEmployee.Code), q.UseParameter("code", DataValueTypes.Text)))
                        .WithParameters(
                ElementFactory.CreateScalar("code", code));

            return(query);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <param name="isPartialUpdate"></param>
        /// <param name="country"></param>
        /// <returns></returns>
        internal IDbQuery QueryUpdateCountry(string code, bool isPartialUpdate, CountryDto country)
        {
            var query = DbFluent.UpdateQuery(Table("Country"))
                        .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                     JoinCondition("Country_RegionalDirectorate")));

            if (!isPartialUpdate || country?.Code?.Length > 0)
            {
                query.AddField(p => DbFluent.FieldAsParameter(nameof(DbCountry.Code), p.UseParameter("code", nameof(DbCountry.Code))));
            }

            return(query);
        }
Ejemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 internal IDbQuery SelectEmployeeWithCode2(string code)
 {
     return(this.UseQuery("SelectEmployeeWithCode2", p =>
                          DbFluent.SelectQuery(Table <DbEmployee>())
                          .From(
                              DbFluent.TableAsJoin(
                                  DbQueryJoinKind.Left,
                                  Table("RegionalDirectorate"),
                                  JoinCondition("Employee_RegionalDirectorate")))
                          .WithFields(Tuple("Fields_SelectEmployee"))
                          .WithLimit(100)
                          .AddIdField(q => DbFluent.FieldAsParameter(nameof(DbEmployee.Code), q.UseParameter("code", DataValueTypes.Text)))
                          .Where(DbFluent.Eq(DbFluent.Field("field1"), DbFluent.Field("field2"))))
            .WithParameters(
                ElementFactory.CreateScalar("code", code)));
 }
Ejemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="q"></param>
 /// <param name="orderBy"></param>
 /// <param name="pageSize"></param>
 /// <param name="pageToken"></param>
 /// <param name="log"></param>
 /// <returns></returns>
 internal IDbQuery ListEmployees1(
     string q, string orderBy, int?pageSize = null, string pageToken = null,
     IBdoLog log = null)
 => DbFluent.SelectQuery("GetMyTables", DbFluent.Table())
 .WithLimit(100)
 .AsDistinct()
 .WithFields(
     DbFluent.FieldAsAll(DbFluent.Table("table")),
     DbFluent.Field("Field1", DbFluent.Table("table")),
     DbFluent.Field("Field2", DbFluent.Table("table")))
 .From(
     DbFluent.Table(nameof(DbRegionalDirectorate).Substring(2), "schema1").WithAlias("table"),
     DbFluent.TableAsJoin(
         DbQueryJoinKind.Left,
         DbFluent.Table("DbTable1".Substring(2), "schema2").WithAlias("table1"),
         DbFluent.And(
             DbFluent.Eq(
                 DbFluent.Field("table1key", DbFluent.Table("table1")),
                 DbFluent.Field(nameof(DbRegionalDirectorate.Code), DbFluent.Table("table"))),
             DbFluent.Eq(
                 DbFluent.Field("table2key", DbFluent.Table("table2")),
                 DbFluent.Field(nameof(DbRegionalDirectorate.LabelEN), DbFluent.Table("table"))))),
     DbFluent.TableAsJoin(
         DbQueryJoinKind.Left,
         DbFluent.Table("DbTable1".Substring(2), "schema2").WithAlias("table2"),
         DbFluent.Eq(
             DbFluent.Field("table1key", DbFluent.Table("table2")),
             DbFluent.Field("Field1", DbFluent.Table("table"))))
     )
 .Filter(
     q,
     DbApiFluent.CreateFilterDefinition(
         DbApiFluent.CreateFilterClause("startDate", DbFluent.Field("CreationDate", DbFluent.Table("table")), DataOperators.GreaterOrEqual),
         DbApiFluent.CreateFilterClause("endDate", DbFluent.Field("LastModificationDate", DbFluent.Table("table")), DataOperators.LesserOrEqual),
         DbApiFluent.CreateFilterClause("code", DbFluent.Field("Code", DbFluent.Table("table")), DataOperators.Equal)),
     log)
 .Sort(
     orderBy,
     DbApiFluent.CreateSortDefinition(
         DbApiFluent.CreateSortClause("startDate", DbFluent.Field("CreationDate", DbFluent.Table("table"))),
         DbApiFluent.CreateSortClause("endDate", DbFluent.Field("LastModificationDate", DbFluent.Table("table"))),
         DbApiFluent.CreateSortClause("code", DbFluent.Field("Code", DbFluent.Table("table")))),
     log);
Ejemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 internal IDbQuery SelectEmployeeWithCode3(string code)
 {
     return(this.UseQuery("SelectEmployeeWithCode3", p =>
                          DbFluent.SelectQuery(null)
                          .From(
                              Table <DbEmployee>(),
                              DbFluent.TableAsJoin(
                                  DbQueryJoinKind.Left,
                                  Table("RegionalDirectorate"),
                                  JoinCondition("Employee_RegionalDirectorate")))
                          .WithFields(Tuple("Fields_SelectEmployee"))
                          .WithLimit(100)
                          .OrderBy(
                              DbFluent.OrderBy(Field <DbEmployee>(p => p.Code, "employee")),
                              DbFluent.OrderBy(Field <DbEmployee>(p => p.DateTimeField, "regionalDirectorate"), DataSortingModes.Descending))
                          .AddIdField(q => DbFluent.FieldAsParameter(nameof(DbEmployee.Code), q.UseParameter("code", DataValueTypes.Text))))
            .WithParameters(
                ElementFactory.CreateScalar("code", code)));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Delete the specified employee.
        /// </summary>
        /// <param name="code">The code to consider.</param>
        /// <returns>Returns the generated query.</returns>
        internal IDbQuery DeleteEmployee8(string code)
        {
            var query = DeleteQuery <DbEmployee>()
                        .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left,
                                     Table("RegionalDirectorate").WithAlias("directorate"),
                                     JoinCondition("Employee_RegionalDirectorate")),
                TableAsJoin <DbContact>(DbQueryJoinKind.Left,
                                        JoinCondition <DbEmployee, DbContact>())
                .WithAlias("mainCountry"),
                DbFluent.TableAsJoin(
                    DbQueryJoinKind.Left,
                    Table <DbContact>().WithAlias("secondaryCountry"),
                    JoinCondition <DbEmployee, DbContact>("secondary")))
                        .Where(q => DataExpressionFactory.CreateExpAsLiteral(@"""Code""='codeC'"))
                        .WithParameters(
                ElementFactory.CreateScalar("code", code));

            return(query);
        }
Ejemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="builder"></param>
        public void OnCreating_Test1()
        {
            AddTable <DbEmployee>(DbFluent.Table(nameof(DbEmployee).Substring(2), "Mdm"))
            .AddTable("RegionalDirectorate", DbFluent.Table(nameof(DbRegionalDirectorate).Substring(2), "Mdm"))
            .AddTable <DbContact>(DbFluent.Table(nameof(DbContact).Substring(2), "Mdm"))

            .AddRelationship("Employee_RegionalDirectorate",
                             Table <DbEmployee>(), Table("RegionalDirectorate"),
                             (nameof(DbEmployee.EmployeeId), nameof(DbRegionalDirectorate.RegionalDirectorateId)))

            .AddRelationship <DbEmployee, DbContact>((p => p.MainContactId, q => q.ContactId))
            .AddRelationship <DbEmployee, DbContact>("secondary", (p => p.MainContactId, q => q.ContactId))

            .AddTuple("Fields_SelectEmployee",
                      DbFluent.FieldAsAll(Table <DbEmployee>()),
                      DbFluent.Field(nameof(DbRegionalDirectorate.RegionalDirectorateId), Table("RegionalDirectorate")),
                      DbFluent.Field(nameof(DbRegionalDirectorate.Code), Table("RegionalDirectorate")))

            .AddTuple("Fields_SelectEmployee2",
                      DbFluent.FieldAsAll(Table <DbEmployee>("employee")),
                      DbFluent.Field <DbContact>(p => p.Code, Table <DbContact>("contact")).WithAlias("contactCode"),
                      DbFluent.Field(nameof(DbRegionalDirectorate.RegionalDirectorateId), Table("RegionalDirectorate", "regionalDirectorate")),
                      DbFluent.Field(nameof(DbRegionalDirectorate.Code), Table("RegionalDirectorate", "regionalDirectorate")))

            .AddQuery(
                DbFluent.StoredQuery(
                    DbFluent.SelectQuery(Table <DbEmployee>())
                    .From(
                        Table <DbEmployee>(),
                        DbFluent.TableAsJoin(
                            DbQueryJoinKind.Left,
                            Table("RegionalDirectorate"),
                            JoinCondition("Employee_RegionalDirectorate")))
                    .WithFields(Tuple("Fields_SelectEmployee"))
                    .AddIdField(p => DbFluent.FieldAsParameter(nameof(DbEmployee.Code), p.UseParameter("code")))));
        }
Ejemplo n.º 15
0
        // As Join -------------------------------------

        /// <summary>
        /// Creates a new joined table.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="kind">The kind to consider.</param>
        /// <param name="condition">The condition to consider.</param>
        /// <returns>Returns a new From statement.</returns>
        public DbJoinedTable TableAsJoin(string name, DbQueryJoinKind kind, DataExpression condition)
        {
            return(DbFluent.TableAsJoin(kind, Table(name), condition));
        }