Pārlūkot izejas kodu

Add entityframework extension support

master
Savorboard pirms 6 gadiem
vecāks
revīzija
467fb54625
2 mainītis faili ar 44 papildinājumiem un 0 dzēšanām
  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 Parādīt failu

@@ -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 Parādīt failu

@@ -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; }
}
}

Notiek ielāde…
Atcelt
Saglabāt