Esempio n. 1
0
        /// <summary>
        /// 如果主键是自增返回插入主键 否则返回0
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public long Insert(AbstractBaseEntity entity)
        {
            long ret;

            using (ConnectionManager mgr = GetConnection())
            {
                using (ISQLMetrics metrics = CreateSQLMetrics())
                {
                    string sql = entity.GetInsertSQL();
                    ret = mgr.Connection.Query <long>(sql, entity, mgr.Transaction, false, null, CommandType.Text).Single();
                    metrics.AddToMetrics(sql, entity);
                }
            }
            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// 异步执行插入操作
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <long> InsertAsync(AbstractBaseEntity entity)
        {
            long ret;

            using (ConnectionManager mgr = GetConnection())
            {
                using (ISQLMetrics metrics = CreateSQLMetrics())
                {
                    var sql = entity.GetInsertSQL();
                    ret = await mgr.Connection.QueryFirstAsync <long>(entity.GetInsertSQL(), entity, mgr.Transaction, null, CommandType.Text);

                    metrics.AddToMetrics(sql, entity);
                }
            }
            return(ret);
        }
Esempio n. 3
0
 public Task <int> UpdateAsync(AbstractBaseEntity model)
 {
     return(ExcuteAsync(model.GetUpdateSQL(), model));
 }
Esempio n. 4
0
 public int Update(AbstractBaseEntity model)
 {
     return(Excute(model.GetUpdateSQL(), model));
 }