Example #1
0
        public IDbScalar <TModel, TReturnType> Where(Expression <Func <TModel, object> > expression)
        {
            _whereExpressionVisitor = new WhereExpressionVisitor().Visit(expression);
            _whereClause            = string.Format(_dbProvider.Dialect.Where, _whereExpressionVisitor.WhereExpression);
            _parameters             = _whereExpressionVisitor.Parameters;

            return(this);
        }
        /// <summary>
        ///     Delete the Database Record based on an expression
        /// </summary>
        /// <typeparam name="TModel">Model Type</typeparam>
        /// <param name="dbProvider">Database Provider</param>
        /// <param name="expression">The expression to use for the query</param>
        /// <remarks>THIS IS A HARD DELETE. When you run this method, the record is GONE!</remarks>
        public static void Delete <TModel>(this IDbProvider dbProvider, Expression <Func <TModel, object> > expression) where TModel : class, new()
        {
            var visitor = new WhereExpressionVisitor().Visit(expression);

            // this is a hard delete. soft deletes will happen in the repository layer.
            var tableName   = typeof(TModel).GetTypeInfo().Name.BuildTableName();
            var whereClause = string.Format(dbProvider.Dialect.Where, visitor.WhereExpression);
            var commandText = string.Format(dbProvider.Dialect.DeleteFrom, tableName, whereClause);

            dbProvider.ExecuteNonQuery(commandText, visitor.Parameters);
        }
Example #3
0
        /// <summary>
        ///     DeleteAsync the Database Record based on an expression
        /// </summary>
        /// <typeparam name="TModel">Model Type</typeparam>
        /// <param name="expression">The expression to use for the query</param>
        /// <remarks>THIS IS A HARD DELETE. When you run this method, the record is GONE!</remarks>
        public Task DeleteAsync <TModel>(Expression <Func <TModel, bool> > expression)
            where TModel : class, new()
        {
            var visitor = new WhereExpressionVisitor().Visit(expression);

            // this is a hard delete. soft deletes will happen in the repository layer.
            var tableName   = typeof(TModel).GetTypeInfo().Name.BuildTableName();
            var whereClause = string.Format(Dialect.Where, visitor.WhereExpression);
            var commandText = string.Format(Dialect.DeleteFrom, tableName, whereClause);

            return(ExecuteNonQueryAsync(commandText, visitor.Parameters));
        }
Example #4
0
        public IDbQuery <TModel> Where(Expression <Func <TModel, object> > expression)
        {
            _whereExpressionVisitor = new WhereExpressionVisitor(_parameters).Visit(expression);
            _parameters             = _whereExpressionVisitor.Parameters;

            if (string.IsNullOrEmpty(_whereClause))
            {
                _whereClause = string.Format(_dbProvider.Dialect.Where, _whereExpressionVisitor.WhereExpression);
            }
            else
            {
                _whereClause += " AND " + _whereExpressionVisitor.WhereExpression;
            }
            return(this);
        }