/// <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))); }
/// <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))))); }