Ejemplo n.º 1
0
        private ModificationStatement CreateStatement(XPClassInfo classInfo, object key, Dictionary <string, object> values)
        {
            if (classInfo == null)
            {
                throw new ArgumentNullException(nameof(classInfo));
            }

            var PropertyIndex = 0;

            DBColumnType keyType = classInfo.Table.GetColumn(classInfo.Table.PrimaryKey.Columns[0]).ColumnType;

            BinaryOperator critera = new BinaryOperator(new QueryOperand(classInfo.KeyProperty.MappingField, null, keyType), new ParameterValue(PropertyIndex)
            {
                Value = key
            }, BinaryOperatorType.Equal);

            UpdateStatement stm = new UpdateStatement(classInfo.Table, "TheTable")
            {
                Condition = critera
            };

            foreach (var item in values)
            {
                DBColumnType mappingFieldDBType = classInfo.GetPersistentMember(item.Key).MappingFieldDBType;
                stm.Operands.Add(new QueryOperand(item.Key, "N" + PropertyIndex, mappingFieldDBType));
                stm.Parameters.Add(new ParameterValue(PropertyIndex)
                {
                    Value = item.Value, DBType = mappingFieldDBType
                });
                PropertyIndex++;
            }
            Debug.WriteLine(stm.ToString());
            //stm.Operands.Add(new QueryOperand(GCRecordField.StaticName, null, DBColumnType.Int32));

            //if (timestamp != null)
            //    stm.Operands.Add(new QueryOperand(TimestampColumnName, null, DBColumnType.DateTime));

            //stm.Parameters.Add(new ParameterValue(propertyIndex++) { Value = gcRecord });

            //if (timestamp != null)
            //    stm.Parameters.Add(new ParameterValue(propertyIndex++) { Value = timestamp });

            return(stm);
        }