Преглед изворни кода

Add entityframework extension support

master
Savorboard пре 6 година
родитељ
комит
467fb54625
2 измењених фајлова са 44 додато и 0 уклоњено
  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 Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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…
Откажи
Сачувај