1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public virtual async Task<T> AddAsync(T entity) { using var connection = _connectionFactory.CreateConnection(); using var transaction = connection.BeginTransaction();
try { var sql = "INSERT INTO EmailMessages (CompanyCode, ApplicationCode, FromAddress, ToAddresses, Subject, Body, ImportanceFlag, HtmlFlag, SplitFlag,Status, SentAt, CreatedAt, UpdatedAt, IsDeleted, UpdatedBy, UpdatedFrom) VALUES (@CompanyCode, @ApplicationCode, @FromAddress, @ToAddresses, @Subject, @Body, @ImportanceFlag, @HtmlFlag, @SplitFlag, @Status, @SentAt, @CreatedAt, @UpdatedAt, @IsDeleted, @UpdatedBy, @UpdatedFrom); SELECT CAST(SCOPE_IDENTITY() as bigint)"; var id = await connection.ExecuteScalarAsync<long>(sql, entity, transaction); var idProperty = typeof(T).GetProperty("Id"); if (idProperty != null) { idProperty.SetValue(entity, id); }
transaction.Commit(); return entity; } catch { transaction.Rollback(); throw; } }
|