Skip to content

Commit

Permalink
Revert TableSelectionSet and IDbContextTransactionManager breaking ch…
Browse files Browse the repository at this point in the history
…anges.

Part of dotnet#10545
  • Loading branch information
AndriySvyryd committed Dec 20, 2017
1 parent 6e260b4 commit 077149c
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/EFCore.InMemory/Diagnostics/InMemoryEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private enum Id

/// <summary>
/// <para>
/// Changes were saved to the database.
/// A transaction operation was requested, but ignored because in-memory does not support transactions.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Database.Transaction" /> category.
Expand All @@ -51,7 +51,7 @@ private enum Id

/// <summary>
/// <para>
/// A transaction operation was requested, but ignored because in-memory does not support transactions.
/// Changes were saved to the database.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Update" /> category.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class InMemoryTransactionManager : IDbContextTransactionManager
public class InMemoryTransactionManager : IDbContextTransactionManager, ITransactionEnlistmentManager
{
private static readonly InMemoryTransaction _stubTransaction = new InMemoryTransaction();

Expand Down Expand Up @@ -86,6 +86,7 @@ public virtual Task<IDbContextTransaction> BeginTransactionAsync(
/// </summary>
public virtual void EnlistTransaction(Transaction transaction)
{
_logger.TransactionIgnoredWarning();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<EnableApiCheck>false</EnableApiCheck>
<IsPackable>true</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(FunctionalTests_PackageVersion)' == '2.0.0'">
<DefineConstants>$(DefineConstants);Test20</DefineConstants>
</PropertyGroup>
Expand Down
98 changes: 98 additions & 0 deletions src/EFCore.Relational/Scaffolding/Internal/TableSelectionSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[Obsolete("This is just to provide backward compatibility for 2.0 providers")]
public class TableSelectionSet
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static readonly TableSelectionSet All = new TableSelectionSet();

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public TableSelectionSet()
: this(Enumerable.Empty<string>(), Enumerable.Empty<string>())
{
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public TableSelectionSet([NotNull] IEnumerable<string> tables)
: this(tables, Enumerable.Empty<string>())
{
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public TableSelectionSet([NotNull] IEnumerable<string> tables, [NotNull] IEnumerable<string> schemas)
{
Check.NotNull(tables, nameof(tables));
Check.NotNull(schemas, nameof(schemas));

Schemas = schemas.Select(schema => new Selection(schema)).ToList();
Tables = tables.Select(table => new Selection(table)).ToList();
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual IReadOnlyList<Selection> Schemas { get; }

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual IReadOnlyList<Selection> Tables { get; }

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class Selection
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public Selection([NotNull] string selectionText)
{
Check.NotEmpty(selectionText, nameof(selectionText));

Text = selectionText;
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string Text { get; }

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual bool IsMatched { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Storage/RelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Microsoft.EntityFrameworkCore.Storage
/// not used in application code.
/// </para>
/// </summary>
public abstract class RelationalConnection : IRelationalConnection
public abstract class RelationalConnection : IRelationalConnection, ITransactionEnlistmentManager
{
private readonly string _connectionString;
private readonly LazyRef<DbConnection> _connection;
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Update/Internal/BatchExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private int Execute(DbContext _, (IEnumerable<ModificationCommandBatch>, IRelati
try
{
if (connection.CurrentTransaction == null
&& connection.EnlistedTransaction == null
&& (connection as ITransactionEnlistmentManager)?.EnlistedTransaction == null
&& Transaction.Current == null
&& CurrentContext.Context.Database.AutoTransactionsEnabled)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ private async Task<int> ExecuteAsync(
try
{
if (connection.CurrentTransaction == null
&& connection.EnlistedTransaction == null
&& (connection as ITransactionEnlistmentManager)?.EnlistedTransaction == null
&& Transaction.Current == null
&& CurrentContext.Context.Database.AutoTransactionsEnabled)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Specification.Tests/UpdatesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public virtual void Remove_partial_on_concurrency_token_original_value_mismatch_
() => context.SaveChanges()).Message);
});
}
#endif

[Fact]
public virtual void Save_replaced_principal()
Expand Down Expand Up @@ -195,6 +194,7 @@ public virtual void Save_replaced_principal()
Assert.Equal(2, products.Count);
});
}
#endif

[Fact]
public virtual void SaveChanges_processes_all_tracked_entities()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static class SqliteServiceCollectionExtensions
/// public void ConfigureServices(IServiceCollection services)
/// {
/// var connectionString = "connection string to database";
///
///
/// services
/// .AddEntityFrameworkSqlite()
/// .AddDbContext&lt;MyContext&gt;((serviceProvider, options) =>
Expand Down Expand Up @@ -79,8 +79,7 @@ public static IServiceCollection AddEntityFrameworkSqlite([NotNull] this IServic
.TryAdd<ICompositeMethodCallTranslator, SqliteCompositeMethodCallTranslator>()
.TryAdd<IQuerySqlGeneratorFactory, SqliteQuerySqlGeneratorFactory>()
.TryAddProviderSpecificServices(
b => b
.TryAddScoped<ISqliteRelationalConnection, SqliteRelationalConnection>());
b => b.TryAddScoped<ISqliteRelationalConnection, SqliteRelationalConnection>());

builder.TryAddCoreServices();

Expand Down
25 changes: 23 additions & 2 deletions src/EFCore/Extensions/TransactionsDatabaseFacadeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;

Expand All @@ -22,14 +23,34 @@ public static class TransactionsDatabaseFacadeExtensions
/// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context.</param>
/// <param name="transaction"> The transaction to be used. </param>
public static void EnlistTransaction([NotNull] this DatabaseFacade databaseFacade, [CanBeNull] Transaction transaction)
=> Check.NotNull(databaseFacade, nameof(databaseFacade)).GetService<IDbContextTransactionManager>().EnlistTransaction(transaction);
{
Check.NotNull(databaseFacade, nameof(databaseFacade));
if (databaseFacade.GetService<IDbContextTransactionManager>() is ITransactionEnlistmentManager transactionManager)
{
transactionManager.EnlistTransaction(transaction);
}
else
{
throw new NotSupportedException(CoreStrings.TransactionsNotSupported);
}
}

/// <summary>
/// Returns the currently enlisted transaction.
/// </summary>
/// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context.</param>
/// <returns> The currently enlisted transaction. </returns>
public static Transaction GetEnlistedTransaction([NotNull] this DatabaseFacade databaseFacade)
=> Check.NotNull(databaseFacade, nameof(databaseFacade)).GetService<IDbContextTransactionManager>().EnlistedTransaction;
{
Check.NotNull(databaseFacade, nameof(databaseFacade));
if (databaseFacade.GetService<IDbContextTransactionManager>() is ITransactionEnlistmentManager transactionManager)
{
return transactionManager.EnlistedTransaction;
}
else
{
throw new NotSupportedException(CoreStrings.TransactionsNotSupported);
}
}
}
}
6 changes: 6 additions & 0 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -829,4 +829,7 @@
<data name="ClashingNonOwnedEntityType" xml:space="preserve">
<value>The type '{entityType}' cannot be marked as owned because a non-owned entity type with the same name already exists.</value>
</data>
<data name="TransactionsNotSupported" xml:space="preserve">
<value>Current provider doesn't support System.Transaction.</value>
</data>
</root>
14 changes: 0 additions & 14 deletions src/EFCore/Storage/IDbContextTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Storage
Expand Down Expand Up @@ -49,17 +47,5 @@ public interface IDbContextTransactionManager : IResettableService
/// Gets the current transaction.
/// </summary>
IDbContextTransaction CurrentTransaction { get; }

/// <summary>
/// The currently enlisted transaction.
/// </summary>
Transaction EnlistedTransaction { get; }

/// <summary>
/// Specifies an existing <see cref="Transaction" /> to be used for database operations.
/// </summary>
/// <param name="transaction"> The transaction to be used. </param>
void EnlistTransaction([CanBeNull] Transaction transaction);

}
}
31 changes: 31 additions & 0 deletions src/EFCore/Storage/ITransactionEnlistmentManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Transactions;
using JetBrains.Annotations;

namespace Microsoft.EntityFrameworkCore.Storage
{
/// <summary>
/// <para>
/// Manages the current <see cref="Transaction" />.
/// </para>
/// <para>
/// This interface is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
public interface ITransactionEnlistmentManager
{
/// <summary>
/// The currently enlisted transaction.
/// </summary>
Transaction EnlistedTransaction { get; }

/// <summary>
/// Specifies an existing <see cref="Transaction" /> to be used for database operations.
/// </summary>
/// <param name="transaction"> The transaction to be used. </param>
void EnlistTransaction([CanBeNull] Transaction transaction);
}
}
10 changes: 0 additions & 10 deletions src/EFCore/breakingchanges.netcore.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
"MemberId": "public const System.Int32 RelationalBaseId = 200000",
"Kind": "Removal"
},
{
"TypeId": "public interface Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager : Microsoft.EntityFrameworkCore.Infrastructure.IResettableService",
"MemberId": "System.Transactions.Transaction get_EnlistedTransaction()",
"Kind": "Addition"
},
{
"TypeId": "public interface Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager : Microsoft.EntityFrameworkCore.Infrastructure.IResettableService",
"MemberId": "System.Void EnlistTransaction(System.Transactions.Transaction transaction)",
"Kind": "Addition"
},
{
"TypeId": "public class Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager>",
"MemberId": "public .ctor(Microsoft.EntityFrameworkCore.DbContext context)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<PropertyGroup Condition="'$(FunctionalTests_PackageVersion)' == '2.0.0'">
<DefineConstants>$(DefineConstants);Test20</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(FunctionalTests_PackageVersion)' == '0.0.0'">
<ProjectReference Include="..\..\src\EFCore.InMemory\EFCore.InMemory.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(FunctionalTests_PackageVersion)' != '0.0.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(FunctionalTests_PackageVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Transactions" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EFCore.Specification.Tests\EFCore.Specification.Tests.csproj" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 077149c

Please sign in to comment.