Exemplo n.º 1
0
        /// <summary>
        /// Execute a query to update only some fields of the give object in database using the <see cref="PrimaryKeyAttribute"/> to identify the record
        /// </summary>
        /// <param name="model">The object to update</param>
        /// <param name="onlyFields">Specify the fields that need to be updated</param>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <returns></returns>
        public async Task <int> UpdateAsync <T, TKey>(T model, Expression <Func <T, TKey> > onlyFields)
        {
            var s = new TypedUpdateStatement <T>(DialectProvider);

            s.ValuesOnly(model, onlyFields);
            var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None);

            return(await this.ExecuteScalarAsync <int>(cmd));
        }
        /// <summary>
        /// Execute a query to update the give object in database using the <see cref="PrimaryKeyAttribute"/> to identify the record
        /// </summary>
        /// <param name="model">the object to update</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public Task <int> UpdateAsync <T>(T model)
        {
            var s = new TypedUpdateStatement <T>(DialectProvider);

            s.ValuesOnly(model);
            var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None);

            return(this.ExecuteScalarAsync <int>(cmd));
        }
Exemplo n.º 3
0
        public async Task <int> UpdateAllAsync <T, TKey>(object obj, Expression <Func <T, TKey> > onlyField, Expression <Func <T, bool> > where = null)
        {
            var s = new TypedUpdateStatement <T>(DialectProvider);

            if (where != null)
            {
                s.Where(where);
            }

            s.Values(obj, onlyField);

            var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None);

            return(await this.ExecuteScalarAsync <int>(cmd));
        }