Browse Source

Add entityframework extension support

master
Savorboard 6 years ago
parent
commit
467fb54625
2 changed files with 44 additions and 0 deletions
  1. +9
    -0
      src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs
  2. +35
    -0
      src/DotNetCore.CAP.MySql/IDbContextTransaction.CAP.cs

+ 9
- 0
src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs View File

@@ -1,6 +1,7 @@
using System.Data;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Infrastructure;

// ReSharper disable once CheckNamespace
namespace DotNetCore.CAP
@@ -60,5 +61,13 @@ namespace DotNetCore.CAP

return transaction;
}

public static IDbContextTransaction BeginAndJoinToTransaction(this DatabaseFacade database,
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();
var capTrans = publisher.Transaction.Begin(trans);
return new CapEFDbTransaction(capTrans);
}
}
}

+ 35
- 0
src/DotNetCore.CAP.MySql/IDbContextTransaction.CAP.cs View File

@@ -0,0 +1,35 @@
using System;
using DotNetCore.CAP;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Storage
{
internal class CapEFDbTransaction : IDbContextTransaction
{
private readonly ICapTransaction _transaction;

public CapEFDbTransaction(ICapTransaction transaction)
{
_transaction = transaction;
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction;
TransactionId = dbContextTransaction.TransactionId;
}

public void Dispose()
{
_transaction.Dispose();
}

public void Commit()
{
_transaction.Commit();
}

public void Rollback()
{
_transaction.Rollback();
}

public Guid TransactionId { get; }
}
}

Loading…
Cancel
Save