Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        protected override Expression VisitMember(MemberExpression m)
        {
            if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter)
            {
                sb.Append(m.Member.Name);
                return(m);
            }
            if (m.Expression != null && m.Expression.NodeType == ExpressionType.MemberAccess)
            {
                var valueTo = GetValue(m);

                string sqlValue = SqlValueConverter.GetSqlValue(valueTo);

                sb.Append(sqlValue);
                return(m);
            }

            throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        private string CompileSql()
        {
            if (Values.Count == 0)
            {
                throw new ArgumentOutOfRangeException("Batch updating must include at least 1 update value. Use Set().");
            }

            StringBuilder updateSQL = new StringBuilder();

            updateSQL.Append($"UPDATE [{TableName}] SET ");
            bool multipleValues = false;

            foreach (var name in Values.Keys)
            {
                if (multipleValues)
                {
                    updateSQL.Append(", ");
                }

                var pair = Values[name];

                updateSQL.Append($"{name} = {SqlValueConverter.GetSqlValue(pair.Item1, (pair.Item2 as PropertyInfo).PropertyType)}");
                multipleValues = true;
            }
            multipleValues = false;
            if (Wheres.Count > 0)
            {
                updateSQL.Append(" WHERE ");

                foreach (var where in Wheres)
                {
                    if (multipleValues)
                    {
                        updateSQL.Append(" AND ");
                    }
                    updateSQL.Append($"({where})");
                    multipleValues = true;
                }
            }

            return(updateSQL.ToString());
        }