コード例 #1
0
        //public int Insert(T entity)
        //{
        //    SqlProvider.FormatInsert(entity);

        //    return Exec(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);
        //}

        public int Insert(T entity)
        {
            SqlProvider.FormatInsert(entity, out var isHaveIdentity, out var property);
            SetSql();
            if (isHaveIdentity == System.ComponentModel.DataAnnotations.IdentityTypeEnum.Int)
            {
                var id = DbCon.ExecuteScalar <int>(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);
                return(id);
            }
            else if (isHaveIdentity == System.ComponentModel.DataAnnotations.IdentityTypeEnum.Guid)
            {
                var gi = DbCon.ExecuteScalar <Guid>(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);
                property.SetValue(entity, gi);
                return(1);
            }
            else
            {
                var r = Exec(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);
                return(r);
            }
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: zl33842901/DapperEx
        public async Task <int> InsertAsync(T entity)
        {
            SqlProvider.FormatInsert(entity, out var isHaveIdentity, out var property);
            SetSql();
            int result;

            if (isHaveIdentity == System.ComponentModel.DataAnnotations.IdentityTypeEnum.Int)
            {
                result = await DbCon.ExecuteScalarAsync <int>(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);
            }
            else if (isHaveIdentity == System.ComponentModel.DataAnnotations.IdentityTypeEnum.Guid)
            {
                var gi = await DbCon.ExecuteScalarAsync <Guid>(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);

                property.SetValue(entity, gi);
                result = 1;
            }
            else
            {
                result = await ExecAsync(SqlProvider.SqlString, SqlProvider.Params, _dbTransaction);
            }
            return(result);
        }
コード例 #3
0
 public int Insert(T entity)
 {
     SqlProvider.FormatInsert(entity);
     return(DbCon.Execute(SqlProvider.SqlString, SqlProvider.Params, DbTransaction));
 }
コード例 #4
0
 public int Insert(T entity, string[] excludeFields = null)
 {
     SqlProvider.FormatInsert(entity, excludeFields);
     return(DbCon.Execute(SqlProvider.SqlString, SqlProvider.Params, DbTransaction));
 }
コード例 #5
0
        public async Task <int> InsertAsync(T entity)
        {
            SqlProvider.FormatInsert(entity);

            return(await DbCon.ExecuteAsync(SqlProvider.SqlString, SqlProvider.Params, DbTransaction));
        }
コード例 #6
0
 public async Task <int> InsertAsync(T entity, string[] excludeFields = null)
 {
     SqlProvider.FormatInsert(entity, excludeFields);
     return(await DbCon.ExecuteAsync(SqlProvider.SqlString, SqlProvider.Params, DbTransaction));
 }
コード例 #7
0
 public async Task <int> InsertAsync(IEnumerable <T> entities, string[] excludeFields = null, int timeout = 120)
 {
     SqlProvider.FormatInsert(entities.FirstOrDefault(), excludeFields);
     return(await DbCon.ExecuteAsync(SqlProvider.SqlString, entities, DbTransaction, timeout));
 }
コード例 #8
0
 public async Task <int> InsertAsync(IEnumerable <T> entities, string[] excludeFields = null, int timeout = 120)
 {
     SqlProvider.FormatInsert(entities, excludeFields);
     return(await DbCon.ExecuteAsync(SqlProvider.SqlString, SqlProvider.Params, DbTransaction, timeout, isExcludeUnitOfWork : SqlProvider.IsExcludeUnitOfWork));
 }
コード例 #9
0
 public int Insert(IEnumerable <T> entities, string[] excludeFields = null, int timeout = 120)
 {
     SqlProvider.FormatInsert(entities.FirstOrDefault(), excludeFields);
     return(DbCon.Execute(SqlProvider.SqlString, entities, DbTransaction, timeout, isExcludeUnitOfWork: SqlProvider.IsExcludeUnitOfWork));
 }