Exemple #1
0
        internal string CreateInsertValuesList()
        {
            var propertiesWithColumnAttr =
                GetType().GetProperties().Where(p => p.GetCustomAttribute <IsColumn>() != null).ToArray();

            var valueList = new StringBuilder();

            if (propertiesWithColumnAttr.Length == 0)
            {
                throw new InvalidOperationException("There are no IsColumn attributes on this object");
            }

            for (var index = 0; index < propertiesWithColumnAttr.Length; index++)
            {
                var property      = propertiesWithColumnAttr[index];
                var column        = property.GetCustomAttribute <IsColumn>();
                var value         = property.GetValue(this);
                var parameterName = RQuery.AddParameter(value, column.ColumnName);
                valueList.Append($"@{parameterName}");

                if (index + 1 < propertiesWithColumnAttr.Length)
                {
                    valueList.Append(",");
                }
            }

            return(valueList.ToString());
        }
Exemple #2
0
        internal string CreateUpdateValuesList(string[] columnsToUpdate)
        {
            var updateList  = new StringBuilder();
            var columnNames = GetColumnNames(true).Where(cn => columnsToUpdate.Length == 0 || columnsToUpdate.Any(cu => cu == cn)).ToArray();

            if (columnNames.Length == 0)
            {
                throw new InvalidOperationException("Could not generate column names. If you specified a column list make sure it matches the IsColumn attributes on your object, otherwise ensure that there are IsColumn attributes applied");
            }

            for (var index = 0; index < columnNames.Length; index++)
            {
                var columnName = columnNames[index];
                var property   = GetPropertyByIsColumnAttribute(columnName);

                if (property == null)
                {
                    continue;
                }

                var value         = property.GetValue(this);
                var parameterName = RQuery.AddParameter(value, columnName);

                updateList.Append($"{columnName} = {parameterName}");

                if (index + 1 < columnNames.Length)
                {
                    updateList.Append(",");
                }
            }

            return(updateList.ToString());
        }
Exemple #3
0
        public NonQuery <T> Delete(T instance)
        {
            RQuery.DtoInstance = instance;
            var parameter = RQuery.AddParameter(instance.GetIdentityColumnValue(), instance.GetIdentityColumnName());

            RQuery.GeneratedSql.Append($"DELETE FROM {instance.GetTableName()} WHERE {instance.GetIdentityColumnName()} = {parameter}");
            return(new NonQuery <T>());
        }
Exemple #4
0
        public static void ProvideIsEqualTo(object value)
        {
            var parameterName = RQuery.AddParameter(value);

            RQuery.GeneratedSql.Append($" = {parameterName}");
        }
Exemple #5
0
        public static void ProvideIsGreaterThan(object value)
        {
            var parameterName = RQuery.AddParameter(value);

            RQuery.GeneratedSql.Append($" > {parameterName}");
        }