Пример #1
0
        /// <summary>An OrmConnection method that gets a scalar.</summary>
        /// <typeparam name="T">   Generic type parameter.</typeparam>
        /// <typeparam name="TKey">Type of the key.</typeparam>

        /// <param name="field">    The field.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The scalar.</returns>
        public TKey GetScalar <T, TKey>(Expression <Func <T, TKey> > field, Expression <Func <T, bool> > predicate)
        {
            //int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50);
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(this.ExecuteScalar <TKey>(DialectProvider.ToSelectStatement(ev.Where(predicate).Select(field), CommandFlags.None)));
        }
        /// <summary>An OrmConnection method that gets a scalar.</summary>
        /// <typeparam name="T">   Generic type parameter.</typeparam>
        /// <typeparam name="TKey">Type of the key.</typeparam>
        /// <param name="field"> The field.</param>
        /// <returns>The scalar.</returns>
        public async Task <TKey> GetScalarAsync <T, TKey>(Expression <Func <T, TKey> > field)
        {
            //int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age));
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(await this.ExecuteScalarAsync <TKey>(DialectProvider.ToSelectStatement(ev.Select(field), CommandFlags.None)));
        }
        /// <summary>An OrmConnection method that first or default.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="predicate">The predicate.</param>
        /// <returns>A T.</returns>
        public async Task <T> FirstOrDefaultAsync <T>(Expression <Func <T, bool> > predicate)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();
            var r  = await SelectAsync(ev.Where(predicate).Limit(1));

            return(r.FirstOrDefault());
        }
Пример #4
0
        /// <summary>An OrmConnection method that inserts an only.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="obj">       The object.</param>
        /// <param name="onlyFields">The only fields.</param>
        public void InsertOnly <T>(T obj, SqlExpressionVisitor <T> onlyFields) where T : new()
        {
            var ev  = DialectProvider.ExpressionVisitor <T>();
            var sql = DialectProvider.ToInsertRowStatement(new[] { obj }, ev.InsertFields);

            this.Execute(sql);
        }
Пример #5
0
        /// <summary>
        /// Update only some fields of an object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="model">Object to update</param>
        /// <param name="onlyFields">Specify the fields to update. ie : x=> x.SomeProperty1 or x=> new{ x.SomeProperty1, x.SomeProperty2}</param>
        /// <returns></returns>
        public int Update <T, TKey>(T model, Expression <Func <T, TKey> > onlyFields)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            ev.Update(onlyFields);
            return(Update(model, ev));
        }
        public async Task <int> UpdateAsync <T, TKey>(T model, Expression <Func <T, TKey> > onlyFields)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            ev.Update(onlyFields);
            return(await UpdateAsync(model, ev));
        }
        /// <summary>An OrmConnection method that inserts an only.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="obj">       The object.</param>
        /// <param name="onlyFields">The only fields.</param>
        public async Task <int> InsertOnlyAsync <T>(T obj, SqlExpressionVisitor <T> onlyFields) where T : new()
        {
            var ev  = DialectProvider.ExpressionVisitor <T>();
            var sql = DialectProvider.ToInsertRowStatement(new[] { obj }, ev.InsertFields);

            return(await this.ExecuteAsync(sql));
        }
Пример #8
0
        /// <summary>An OrmConnection method that selects.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="expression">The ev.</param>
        /// <param name="buffered"></param>
        /// <returns>A List&lt;T&gt;</returns>
        public IEnumerable <T> Select <T>(Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > expression,
                                          CommandFlags flags = CommandFlags.Buffered)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(this.Query <T>(DialectProvider.ToSelectStatement(expression(ev), flags)));
        }
        /// <summary>An OrmConnection method that inserts an only.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="obj">       The object.</param>
        /// <param name="onlyFields">The only fields.</param>
        public async Task <int> InsertOnlyAsync <T>(T obj, Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > onlyFields)
            where T : new()
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(await InsertOnlyAsync(obj, onlyFields(ev)));
        }
Пример #10
0
        /// <summary>An OrmConnection method that deletes this object.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="where"> The where.</param>
        /// <returns>An int.</returns>
        public async Task <int> DeleteAllAsync <T>(Expression <Func <T, bool> > where = null)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            if (where != null)
            {
                ev.Where(where);
            }
            return(await DeleteAllAsync(ev.Where(where)));
        }
Пример #11
0
        /// <param name="where"> The where.</param>
        /// <returns>An int.</returns>
        public int DeleteAll <T>(Expression <Func <T, bool> > where = null)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            if (where != null)
            {
                ev.Where(where);
            }
            return(DeleteAll(ev));
        }
Пример #12
0
        public async Task <int> UpdateAllAsync <T, TKey>(T obj, Expression <Func <T, TKey> > onlyField, Expression <Func <T, bool> > where = null)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            ev.Where(where);
            if (onlyField != null)
            {
                ev.Update(onlyField);
            }
            return(await UpdateAllAsync <T>(obj, ev));
        }
Пример #13
0
        /// <summary>
        /// Update all object of a given type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">New values</param>
        /// <param name="onlyField">Fields to update</param>
        /// <param name="where">Where clause</param>
        /// <returns></returns>
        public int UpdateAll <T>(object obj, Expression <Func <T, bool> > where = null, Expression <Func <T, object> > onlyField = null)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            ev.Where(where);
            if (onlyField != null)
            {
                ev.Update(onlyField);
            }
            return(UpdateAll <T>(obj, ev));
        }
Пример #14
0
        /// <summary>
        /// Update all properties of object instance
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model">Object to update</param>
        /// <returns></returns>
        public int Update <T>(T model)
        {
            var cmd = DialectProvider.ToUpdateRowStatement(model, DialectProvider.ExpressionVisitor <T>());

            return(this.ExecuteScalar <int>(cmd));
        }
Пример #15
0
        /// <summary>
        ///    An OrmConnection method that counts the given database connection.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>

        public long Count <T>()
        {
            return(Count(DialectProvider.ExpressionVisitor <T>()));
        }
Пример #16
0
        /// <summary>An OrmConnection method that selects.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="predicate">The predicate.</param>
        /// <param name="buffered"></param>
        /// <param name="flags"></param>
        /// <returns>A List&lt;T&gt;</returns>
        public IEnumerable <T> Select <T>(Expression <Func <T, bool> > predicate, CommandFlags flags = CommandFlags.Buffered)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(this.Query <T>(DialectProvider.ToSelectStatement(ev.Where(predicate), flags)));
        }
Пример #17
0
        /// <summary>
        ///    An OrmConnection method that counts the given database connection.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="expression">The ev.</param>
        /// <returns>A long.</returns>
        public long Count <T>(Expression <Func <T, bool> > expression)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(Count(ev.Where(expression)));
        }
Пример #18
0
 /// <summary>
 ///    An OrmConnection method that counts the given database connection.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <returns>A long.</returns>
 public async Task <long> CountAsync <T>()
 {
     return(await CountAsync(DialectProvider.ExpressionVisitor <T>()));
 }
Пример #19
0
 /// <summary>An OrmConnection method that selects.</summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <returns>A List&lt;T&gt;</returns>
 public async Task <IEnumerable <T> > SelectAsync <T>(CommandFlags flags = CommandFlags.Buffered)
 {
     return(await this.QueryAsync <T>(DialectProvider.ToSelectStatement(DialectProvider.ExpressionVisitor <T>(), flags)));
 }
Пример #20
0
 /// <summary>An OrmConnection method that deletes this object.</summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="where"> The where.</param>
 /// <returns>An int.</returns>
 public async Task <int> DeleteAllAsync <T>(Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > where)
 {
     return(await DeleteAllAsync(where (DialectProvider.ExpressionVisitor <T>())));
 }
Пример #21
0
        /// <summary>An OrmConnection method that inserts an only.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="obj">       The object.</param>
        /// <param name="onlyFields">The only fields.</param>
        public void InsertOnly <T>(T obj, Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > onlyFields) where T : new()
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            InsertOnly(obj, onlyFields(ev));
        }
Пример #22
0
        public async Task <int> UpdateAsync <T>(T model)
        {
            var cmd = DialectProvider.ToUpdateRowStatement(model, DialectProvider.ExpressionVisitor <T>());

            return(await this.ExecuteScalarAsync <int>(cmd));
        }
Пример #23
0
 /// <summary>An OrmConnection method that selects.</summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="buffered"></param>
 /// <returns>A List&lt;T&gt;</returns>
 public IEnumerable <T> Select <T>(CommandFlags flags = CommandFlags.Buffered)
 {
     return(this.Query <T>(DialectProvider.ToSelectStatement(DialectProvider.ExpressionVisitor <T>(), flags)));
 }
Пример #24
0
        public async Task <long> CountAsync <T>(Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > expression)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(await this.ExecuteScalarAsync <long>(DialectProvider.ToCountStatement(expression(ev))));
        }
Пример #25
0
 /// <summary>An OrmConnection method that deletes this object.</summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="where"> The where.</param>
 /// <returns>An int.</returns>
 public int DeleteAll <T>(Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > where)
 {
     return(DeleteAll(where (DialectProvider.ExpressionVisitor <T>())));
 }
Пример #26
0
        /// <summary>
        ///    An OrmConnection method that counts the given database connection.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="expression">The expression.</param>
        /// <returns>A long.</returns>
        public async Task <long> CountAsync <T>(Expression <Func <T, bool> > expression)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(await CountAsync(ev.Where(expression)));
        }
Пример #27
0
        /// <summary>An OrmConnection method that first or default.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>

        /// <param name="predicate">The predicate.</param>
        /// <returns>A T.</returns>
        public T FirstOrDefault <T>(Expression <Func <T, bool> > predicate)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(Select(ev.Where(predicate).Limit(1)).FirstOrDefault());
        }
Пример #28
0
        public long Count <T>(Func <SqlExpressionVisitor <T>, SqlExpressionVisitor <T> > expression)
        {
            var ev = DialectProvider.ExpressionVisitor <T>();

            return(this.ExecuteScalar <long>(DialectProvider.ToCountStatement(expression(ev))));
        }