Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="table"></param>
        /// <param name="expressions"></param>
        /// <returns></returns>
        public IBdoDbModelBuilder AddTable <T>(DbTable table, params Expression <Func <T, object> >[] expressions) where T : class
        {
            Type type      = typeof(T);
            var  tableName = type.Name;

            if (table == null)
            {
                table = new DbTable
                {
                    Name = tableName
                };
                if (type.GetCustomAttribute(typeof(BdoDbTableAttribute)) is BdoDbTableAttribute tableAttribute)
                {
                    table.Name       = tableAttribute.Name;
                    table.Schema     = tableAttribute.Schema;
                    table.DataModule = tableAttribute.DataModule;
                }
            }

            List <DbField> fields = new List <DbField>();

            foreach (var expression in expressions)
            {
                fields.Add(DbFluent.Field(expression.GetProperty().Name));
            }

            AddTable(tableName, table, fields.ToArray());

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete the specified employee.
        /// </summary>
        /// <param name="code">The code to consider.</param>
        /// <returns>Returns the generated query.</returns>
        internal IDbQuery DeleteEmployee5(string code)
        {
            var query = DbFluent.DeleteQuery(Table <DbEmployee>())
                        .Where(q => DbFluent.Eq(DbFluent.Field("code"), code));

            return(query);
        }
Ejemplo n.º 3
0
        // Join conditions ---------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="table1Alias"></param>
        /// <param name="table2Alias"></param>
        /// <returns></returns>
        public DataExpression JoinCondition(
            string name,
            string table1Alias = null,
            string table2Alias = null)
        {
            DbTableRelationship relationship = Relationship(name);

            if (!string.IsNullOrEmpty(table1Alias))
            {
                relationship.Table1.Alias = table1Alias;
            }
            if (!string.IsNullOrEmpty(table2Alias))
            {
                relationship.Table2.Alias = table2Alias;
            }

            List <object> queryConditions = new List <object>();

            foreach (var mapping in relationship.FieldMappingDictionary.Values)
            {
                queryConditions.Add(
                    DbFluent.Eq(
                        DbFluent.Field(mapping.Key, relationship.Table1),
                        DbFluent.Field(mapping.Content, relationship.Table2)));
            }

            return(DbFluent.And(queryConditions.ToArray()));
        }
Ejemplo n.º 4
0
        public void TestInterprete_Fun_SqlEq()
        {
            var log = new BdoLog();

            string value        = null;
            string fluentScript = DbFluent.Eq(
                DbFluent.Field("RegionalDirectorateId"), DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId")));
            string expectedScript = "$sqlEq($sqlField('RegionalDirectorateId'), $sqlIfNull($sqlNull(), $sqlField('RegionalDirectorateId')))";

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(expectedScript.Equals(fluentScript, StringComparison.OrdinalIgnoreCase), "Bad fluent interpretation. Result was '" + xml);


            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string expectedResult = @"""RegionalDirectorateId""=COALESCE(NULL, ""RegionalDirectorateId"")";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
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 DeleteEmployee4(string code)
        {
            var query = DbFluent.DeleteQuery(Table <DbEmployee>())
                        .Where(q => DbFluent.Eq(DbFluent.Field("code"), q.UseParameter("code", DataValueTypes.Text)))
                        .WithParameters(
                ElementFactory.CreateScalar("code", code));

            return(query);
        }
Ejemplo n.º 6
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.º 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
        public void AddFields()
        {
            var log = new BdoLog();

            var tuple = DbFluent.Tuple(
                DbFluent.Field("field1", DbFluent.Table("Table1")),
                DbFluent.Field("field2", DbFluent.Table("Table1")),
                DbFluent.Field("field3", DbFluent.Table("Table1")).WithAlias("f3"))
                        .AddFields(
                DbFluent.FieldAsLiteral("field1", 1),
                DbFluent.FieldAsLiteral("field2", DbFluent.Table("Table2"), 2).WithAlias("f3"));

            Assert.That(tuple.Fields.Count == 3, "Bad script interpretation");
        }
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)));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        internal IDbQuery InsertEmployee3(EmployeeDto employee)
        {
            return(DbFluent.InsertQuery(Table <DbEmployee>())
                   .WithFields(q => new[]
            {
                DbFluent.Field(nameof(DbEmployee.Code)),
                DbFluent.Field(nameof(DbEmployee.ByteArrayField)),
                DbFluent.Field(nameof(DbEmployee.DoubleField)),
                DbFluent.Field(nameof(DbEmployee.DateTimeField)),
                DbFluent.Field(nameof(DbEmployee.LongField))
            })
                   .WithReturnedIdFields(new[]
            {
                Field <DbEmployee>(p => p.EmployeeId)
            })
                   .From(p => p.UseSubQuery(
                             DbFluent.SelectQuery(Table <DbEmployee>())
                             .WithFields(q => new[]
            {
                DbFluent.FieldAsParameter(nameof(DbEmployee.Code), q.UseParameter("newCode", DataValueTypes.Text)),
                DbFluent.FieldAsParameter(nameof(DbEmployee.ByteArrayField), q.UseParameter("ByteArrayField", DataValueTypes.Text)),
                DbFluent.FieldAsParameter(nameof(DbEmployee.DoubleField), q.UseParameter("DoubleField", DataValueTypes.Text)),
                DbFluent.FieldAsParameter(nameof(DbEmployee.DateTimeField), q.UseParameter("DateTimeField", DataValueTypes.Text)),
                DbFluent.FieldAsParameter(nameof(DbEmployee.LongField), q.UseParameter("LongField", DataValueTypes.Date)),

                DbFluent.FieldAsQuery <DbContact>(p => p.ContactId,
                                                  DbFluent.SelectQuery(Table <DbContact>())
                                                  .WithLimit(1)
                                                  .AddField(Field <DbContact>(f => f.ContactId))
                                                  .AddIdField(
                                                      DbFluent.FieldAsParameter <DbContact>(f => f.Code, q.UseParameter("contactCode", DataValueTypes.Text)))),
            })
                             .WithIdFields(q => new[]
            {
                DbFluent.FieldAsParameter(nameof(DbEmployee.Code), q.UseParameter("oldCode", DataValueTypes.Text))
            })
                             .WithParameters(
                                 ElementFactory.CreateScalar("newCode", employee.Code),
                                 ElementFactory.CreateScalar("contactCode", "contactCodeA"),
                                 ElementFactory.CreateScalar("oldCode", "oldCode"),
                                 ElementFactory.CreateScalar("ByteArrayField", employee.ByteArrayField),
                                 ElementFactory.CreateScalar("DoubleField", employee.DoubleField),
                                 ElementFactory.CreateScalar("DateTimeField", employee.DateTimeField),
                                 ElementFactory.CreateScalar("LongField", employee.LongField)))));
        }
Ejemplo n.º 12
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.º 13
0
        public void TestInterprete_Fun_SqlEq_Null()
        {
            var log = new BdoLog();

            // Case: value, null

            string value         = null;
            string fluentScript1 = DbFluent.Eq(
                null, DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId", DbFluent.Table("Table1", "Schema1"))));

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript1, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string expectedResult = @"COALESCE(NULL, ""Schema1"".""Table1"".""RegionalDirectorateId"") is null";

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);

            // Case: null, value

            string fluentScript2 = DbFluent.Eq(
                DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId", DbFluent.Table("Table1", "Schema1"))), null);

            result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript2, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            expectedResult = @"COALESCE(NULL, ""Schema1"".""Table1"".""RegionalDirectorateId"") is null";

            xml = "";
            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Updates the regional directorate of the specified Fidal employee.
 /// </summary>
 /// <param name="regionalDirectorateCode">The code of the regional directorate to consider.</param>
 /// <returns>Returns the query.</returns>
 internal IDbQuery UpdateEmployee2(string regionalDirectorateCode)
 {
     return(this.UseQuery("UpdateEmployee2", p =>
                          DbFluent.UpdateQuery(Table("DbEmployee", "employee"))
                          .AddField(q => DbFluent.Field <DbEmployee>(q => q.RegionalDirectorateId).AsNull())
                          .From(Table("RegionalDirectorate", "regionalDirectorate"))
                          .AddIdField(q =>
                                      DbFluent.FieldAsOther <DbEmployee>(
                                          t => t.RegionalDirectorateId, Table("DbEmployee", "employee"),
                                          DbFluent.Field <DbRegionalDirectorate>(
                                              t => t.RegionalDirectorateId, Table("RegionalDirectorate").WithAlias("regionalDirectorate"))))
                          .AddIdField(q =>
                                      DbFluent.FieldAsParameter <DbEmployee>(
                                          t => t.Code,
                                          DbFluent.Table("employee"),
                                          q.UseParameter("regionalDirectorateCode", DataValueTypes.Text)))
                          .WithReturnedIdFields(Field("Code", "DbEmployee", "employee"))
                          )
            .WithParameters(
                ElementFactory.CreateScalar("regionalDirectorateCode", regionalDirectorateCode)));
 }
Ejemplo n.º 15
0
        public void TestInterprete_Fun_SqlULPad()
        {
            var log = new BdoLog();

            string fluentScript = DbFluent.LeftPadding(DbFluent.Field("RegionalDirectorateId"), 10, DbFluent.Text("A"));

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string expectedResult = @"lpad(""RegionalDirectorateId"", 10, 'A')";

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Ejemplo n.º 16
0
        public void TestInterprete_Fun_SqlIf()
        {
            string value   = null;
            string script1 = DbFluent.If(DbFluent.IsNull(value), DbFluent.Field("RegionalDirectorateId"), DbFluent.Field("RegionalDirectorateId2"));

            string expectedResult = @"case when (null is null) then ""RegionalDirectorateId"" else ""RegionalDirectorateId2"" end";

            var log = new BdoLog();

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script1, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Ejemplo n.º 17
0
        public void TestInterprete_Fun_SqlEncode()
        {
            string script         = DbFluent.EncodeBase64(DbFluent.Text("ABCDE"));
            string expectedResult = @"encode('ABCDE', 'base64')";

            var log = new BdoLog();

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);

            script         = DbFluent.DecodeBase64(DbFluent.Field("ABCDE"));
            expectedResult = @"decode(""ABCDE"", 'base64')";
            log            = new BdoLog();

            scriptVariableSet = new ScriptVariableSet();
            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            xml = "";
            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Ejemplo n.º 18
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.º 19
0
        public void TestSqlIfNull()
        {
            var expression = DbFluent.Eq(
                DbFluent.Field("fieldA"),
                DbFluent.IfNull(
                    DbFluent.Parameter("myText"),
                    DbFluent.Field("fieldA")));
            var log = new BdoLog();

            string expectedResult = @"""fieldA""=coalesce(|*|p:myText|*|, ""fieldA"")";

            var result = _appHost.Interpreter.Evaluate <string>(
                expression,
                new ScriptVariableSet().SetDbBuilder(new DbQueryBuilder_PostgreSql()),
                log: log);

            var xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Ejemplo n.º 20
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="expression"></param>
 /// <param name="tableAlias"></param>
 /// <returns></returns>
 public DbField Field <T>(Expression <Func <T, object> > expression, string tableAlias = null)
 {
     return(DbFluent.Field(expression.GetProperty().Name, Table <T>(tableAlias)));
 }
Ejemplo n.º 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="tableName"></param>
 /// <param name="tableAlias"></param>
 /// <returns></returns>
 public DbField Field(string name, string tableName, string tableAlias = null)
 {
     return(DbFluent.Field(name, Table(tableName, tableAlias)));
 }
Ejemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        public void OnCreating_Test2()
        {
            // Community

            AddTable <DbCommunity>(
                DbFluent.Table(nameof(DbCommunity).Substring(2), DbSchemas.Test2.ToString()),
                q => q.CommunityId,
                q => q.Code,
                q => q.CreationDate,
                q => q.LabelEN,
                q => q.LabelFR,
                q => q.LastModificationDate)
            .AddTuple(
                "SelectCommunity",
                AllFields <DbCommunity>().ToArray()
                )
            .AddTuple(
                "UpdateCommunity",
                DbFluent.Field(nameof(DbCommunity.Code), Table <DbCommunity>()),
                Field <DbCommunity>(q => q.LabelEN),
                Field(nameof(DbCommunity.LabelFR), "DbCommunity"),
                DbFluent.Field(nameof(DbCommunity.LastModificationDate), Table <DbCommunity>())
                );

            // Country

            AddTable <DbCountry>(
                DbFluent.Table(nameof(DbCountry).Substring(2), DbSchemas.Test2.ToString()),
                q => q.CountryId,
                q => q.Code,
                q => q.CreationDate,
                q => q.LabelEN,
                q => q.LabelFR,
                q => q.LastModificationDate)
            .AddTuple(
                "SelectCountry",
                Field <DbCountry>(q => q.CountryId),
                DbFluent.Field(nameof(DbCountry.Code), Table <DbCountry>()),
                DbFluent.Field(nameof(DbCountry.CreationDate)),
                DbFluent.Field(nameof(DbCountry.LabelEN)),
                DbFluent.Field(nameof(DbCountry.LabelFR)),
                DbFluent.Field(nameof(DbCountry.LastModificationDate)))
            .AddTuple(
                "UpdateCountry",
                DbFluent.Field(nameof(DbCountry.Code)),
                DbFluent.Field(nameof(DbCountry.LabelEN)),
                DbFluent.Field(nameof(DbCountry.LabelFR)),
                DbFluent.Field(nameof(DbCountry.LastModificationDate)));

            // Country_Community

            AddTable("Country_Community", DbFluent.Table(nameof(DbCountry_Community).Substring(2), DbSchemas.Test2.ToString()))
            .AddTuple(
                "SelectCountry_Community",
                DbFluent.Field(nameof(DbCountry_Community.CountryId), Table("Country_Community")),
                DbFluent.Field(nameof(DbCountry_Community.CommunityId), Table("Country_Community")))
            .AddTuple(
                "UpdateCountry",
                DbFluent.Field(nameof(DbCountry_Community.CountryId), Table("Country_Community")),
                DbFluent.Field(nameof(DbCountry_Community.CommunityId), Table("Country_Community")));

            // CountryInformation

            AddTable <DbCountryInformation>(
                DbFluent.Table(nameof(DbCountryInformation).Substring(2), DbSchemas.Test2.ToString()))
            .AddTuple(
                "SelectCountryInformation",
                DbFluent.Field(nameof(DbCountryInformation.CountryId)),
                DbFluent.Field(nameof(DbCountryInformation.CreationDate)),
                DbFluent.Field(nameof(DbCountryInformation.LastModificationDate)),
                DbFluent.Field(nameof(DbCountryInformation.StartDate)))
            .AddTuple(
                "UpdateCountryInformation",
                DbFluent.Field(nameof(DbCountryInformation.LastModificationDate)),
                DbFluent.Field(nameof(DbCountryInformation.StartDate)));

            // Relationships

            AddRelationship(
                "Community_Country_Community",
                Table <DbCommunity>(),
                Table("Country_Community"),
                (nameof(DbCommunity.CommunityId), nameof(DbCountry_Community.CommunityId)))
            .AddRelationship(
                "Community_Country_Community",
                Table <DbCountry>(),
                Table("Country_Community"),
                (nameof(DbCountry.CountryId), nameof(DbCountry_Community.CountryId)))
            .AddRelationship <DbCountryInformation, DbCountry>(
                (q => q.CountryId, q => q.CountryId));
        }