瀏覽代碼

fixed issue #25

master
yangxiaodong 7 年之前
父節點
當前提交
a9e0743f07
共有 3 個文件被更改,包括 25 次插入13 次删除
  1. +8
    -4
      src/DotNetCore.CAP.MySql/CapPublisher.cs
  2. +8
    -4
      src/DotNetCore.CAP.PostgreSql/CapPublisher.cs
  3. +9
    -5
      src/DotNetCore.CAP.SqlServer/CapPublisher.cs

+ 8
- 4
src/DotNetCore.CAP.MySql/CapPublisher.cs 查看文件

@@ -34,13 +34,17 @@ namespace DotNetCore.CAP.MySql
protected override void PrepareConnectionForEF()
{
DbConnection = _dbContext.Database.GetDbConnection();
var transaction = _dbContext.Database.CurrentTransaction;
if (transaction == null)
var dbContextTransaction = _dbContext.Database.CurrentTransaction;
var dbTrans = dbContextTransaction?.GetDbTransaction();
//DbTransaction is dispose in original
if (dbTrans?.Connection == null)
{
IsCapOpenedTrans = true;
transaction = _dbContext.Database.BeginTransaction(IsolationLevel.ReadCommitted);
dbContextTransaction?.Dispose();
dbContextTransaction = _dbContext.Database.BeginTransaction(IsolationLevel.ReadCommitted);
dbTrans = dbContextTransaction.GetDbTransaction();
}
DbTranasaction = transaction.GetDbTransaction();
DbTranasaction = dbTrans;
}

protected override void Execute(IDbConnection dbConnection, IDbTransaction dbTransaction, CapPublishedMessage message)


+ 8
- 4
src/DotNetCore.CAP.PostgreSql/CapPublisher.cs 查看文件

@@ -34,13 +34,17 @@ namespace DotNetCore.CAP.PostgreSql
protected override void PrepareConnectionForEF()
{
DbConnection = _dbContext.Database.GetDbConnection();
var transaction = _dbContext.Database.CurrentTransaction;
if (transaction == null)
var dbContextTransaction = _dbContext.Database.CurrentTransaction;
var dbTrans = dbContextTransaction?.GetDbTransaction();
//DbTransaction is dispose in original
if (dbTrans?.Connection == null)
{
IsCapOpenedTrans = true;
transaction = _dbContext.Database.BeginTransaction(IsolationLevel.ReadCommitted);
dbContextTransaction?.Dispose();
dbContextTransaction = _dbContext.Database.BeginTransaction(IsolationLevel.ReadCommitted);
dbTrans = dbContextTransaction.GetDbTransaction();
}
DbTranasaction = transaction.GetDbTransaction();
DbTranasaction = dbTrans;
}

protected override void Execute(IDbConnection dbConnection, IDbTransaction dbTransaction, CapPublishedMessage message)


+ 9
- 5
src/DotNetCore.CAP.SqlServer/CapPublisher.cs 查看文件

@@ -1,5 +1,6 @@
using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
using DotNetCore.CAP.Abstractions;
@@ -34,13 +35,17 @@ namespace DotNetCore.CAP.SqlServer
protected override void PrepareConnectionForEF()
{
DbConnection = _dbContext.Database.GetDbConnection();
var transaction = _dbContext.Database.CurrentTransaction;
if (transaction == null)
var dbContextTransaction = _dbContext.Database.CurrentTransaction;
var dbTrans = dbContextTransaction?.GetDbTransaction();
//DbTransaction is dispose in original
if (dbTrans?.Connection == null)
{
IsCapOpenedTrans = true;
transaction = _dbContext.Database.BeginTransaction(IsolationLevel.ReadCommitted);
dbContextTransaction?.Dispose();
dbContextTransaction = _dbContext.Database.BeginTransaction(IsolationLevel.ReadCommitted);
dbTrans = dbContextTransaction.GetDbTransaction();
}
DbTranasaction = transaction.GetDbTransaction();
DbTranasaction = dbTrans;
}

protected override void Execute(IDbConnection dbConnection, IDbTransaction dbTransaction, CapPublishedMessage message)
@@ -53,7 +58,6 @@ namespace DotNetCore.CAP.SqlServer
protected override async Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, CapPublishedMessage message)
{
await dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction);

_logger.LogInformation("Published Message has been persisted in the database. name:" + message.ToString());
}



Loading…
取消
儲存