Skip to content

Commit

Permalink
Make CSharpRuntimeAnnotationCodeGenerator and friends internal
Browse files Browse the repository at this point in the history
Make UpdateEntryEventData derive from DbContextEventData

Part of #24743
  • Loading branch information
AndriySvyryd committed Jul 28, 2021
1 parent 423a107 commit 27fa24d
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;

namespace Microsoft.EntityFrameworkCore.InMemory.Design.Internal
{
Expand All @@ -11,6 +11,7 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Design.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
#pragma warning disable EF1001 // Internal EF Core API usage.
public class InMemoryCSharpRuntimeAnnotationCodeGenerator : CSharpRuntimeAnnotationCodeGenerator
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -28,8 +29,10 @@ public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollec
Check.NotNull(serviceCollection, nameof(serviceCollection));

serviceCollection.AddEntityFrameworkInMemoryDatabase();
#pragma warning disable EF1001 // Internal EF Core API usage.
new EntityFrameworkDesignServicesBuilder(serviceCollection)
.TryAdd<ICSharpRuntimeAnnotationCodeGenerator, InMemoryCSharpRuntimeAnnotationCodeGenerator>()
#pragma warning restore EF1001 // Internal EF Core API usage.
.TryAddCoreServices();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -77,7 +78,9 @@ protected override ServiceCharacteristics GetServiceCharacteristics(Type service
public override EntityFrameworkServicesBuilder TryAddCoreServices()
{
TryAdd<IAnnotationCodeGenerator, AnnotationCodeGenerator>();
#pragma warning disable EF1001 // Internal EF Core API usage.
TryAdd<ICSharpRuntimeAnnotationCodeGenerator, RelationalCSharpRuntimeAnnotationCodeGenerator>();
#pragma warning restore EF1001 // Internal EF Core API usage.

ServiceCollectionMap.GetInfrastructure()
.AddDependencySingleton<AnnotationCodeGeneratorDependencies>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// <para>
/// Base class to be used by relational database providers when implementing an <see cref="ICSharpRuntimeAnnotationCodeGenerator" />
/// </para>
/// </summary>
#pragma warning disable EF1001 // Internal EF Core API usage.
public class RelationalCSharpRuntimeAnnotationCodeGenerator : CSharpRuntimeAnnotationCodeGenerator
{
/// <summary>
Expand Down Expand Up @@ -137,12 +138,12 @@ private void Create(
var method = function.MethodInfo;
mainBuilder.AppendLine(",")
.Append("methodInfo: ").Append(code.Literal(method.DeclaringType!)).AppendLine(".GetMethod(").IncrementIndent()
.Append(code.Literal(method.Name)).AppendLine(",")
.Append(code.Literal(method.Name!)).AppendLine(",")
.Append(method.IsPublic ? "BindingFlags.Public" : "BindingFlags.NonPublic")
.Append(method.IsStatic ? " | BindingFlags.Static" : " | BindingFlags.Instance")
.AppendLine(" | BindingFlags.DeclaredOnly,")
.AppendLine("null,")
.Append("new Type[] { ").Append(string.Join(", ", method.GetParameters().Select(p => code.Literal(p.ParameterType)))).AppendLine(" },")
.Append("new Type[] { ").Append(string.Join(", ", method.GetParameters().Select(p => code.Literal((Type)p.ParameterType)))).AppendLine(" },")
.Append("null)").DecrementIndent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,17 @@ public static bool IsConcurrencyTokenMissing(

private static void RemoveDerivedEntityTypes<T>(Dictionary<IConventionEntityType, T> entityTypeDictionary)
{
var entityTypesWithDerivedTypes =
entityTypeDictionary.Where(e => e.Key.GetDirectlyDerivedTypes().Any());
foreach (var entityType in entityTypeDictionary.Where(e => e.Key.BaseType != null))
foreach (var entityType in entityTypeDictionary.Keys)
{
foreach (var otherEntityType in entityTypesWithDerivedTypes)
var baseType = entityType.BaseType;
while (baseType != null)
{
if (otherEntityType.Equals(entityType))
if (entityTypeDictionary.ContainsKey(baseType))
{
continue;
}

if (otherEntityType.Key.IsAssignableFrom(entityType.Key))
{
entityTypeDictionary.Remove(entityType.Key);
entityTypeDictionary.Remove(entityType);
break;
}
baseType = baseType.BaseType;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal;

Expand All @@ -13,6 +13,7 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Design.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
#pragma warning disable EF1001 // Internal EF Core API usage.
public class SqlServerCSharpRuntimeAnnotationCodeGenerator : RelationalCSharpRuntimeAnnotationCodeGenerator
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -30,9 +31,11 @@ public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollec
Check.NotNull(serviceCollection, nameof(serviceCollection));

serviceCollection.AddEntityFrameworkSqlServer();
#pragma warning disable EF1001 // Internal EF Core API usage.
new EntityFrameworkRelationalDesignServicesBuilder(serviceCollection)
.TryAdd<IAnnotationCodeGenerator, SqlServerAnnotationCodeGenerator>()
.TryAdd<ICSharpRuntimeAnnotationCodeGenerator, SqlServerCSharpRuntimeAnnotationCodeGenerator>()
#pragma warning restore EF1001 // Internal EF Core API usage.
.TryAdd<IDatabaseModelFactory, SqlServerDatabaseModelFactory>()
.TryAdd<IProviderConfigurationCodeGenerator, SqlServerCodeGenerator>()
.TryAddCoreServices();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal;

Expand All @@ -13,6 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Design.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
#pragma warning disable EF1001 // Internal EF Core API usage.
public class SqliteCSharpRuntimeAnnotationCodeGenerator : RelationalCSharpRuntimeAnnotationCodeGenerator
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -27,8 +28,10 @@ public class SqliteDesignTimeServices : IDesignTimeServices
public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddEntityFrameworkSqlite();
#pragma warning disable EF1001 // Internal EF Core API usage.
new EntityFrameworkRelationalDesignServicesBuilder(serviceCollection)
.TryAdd<ICSharpRuntimeAnnotationCodeGenerator, SqliteCSharpRuntimeAnnotationCodeGenerator>()
#pragma warning restore EF1001 // Internal EF Core API usage.
.TryAdd<IDatabaseModelFactory, SqliteDatabaseModelFactory>()
.TryAdd<IProviderConfigurationCodeGenerator, SqliteCodeGenerator>()
.TryAddCoreServices();
Expand Down
1 change: 1 addition & 0 deletions src/EFCore/Design/EntityFrameworkDesignServicesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// The parameter object for a <see cref="ICSharpRuntimeAnnotationCodeGenerator" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Microsoft.EntityFrameworkCore.Metadata;

namespace Microsoft.EntityFrameworkCore.Design
namespace Microsoft.EntityFrameworkCore.Design.Internal
{
/// <summary>
/// Implemented by database providers to generate the code for annotations.
Expand Down
5 changes: 3 additions & 2 deletions src/EFCore/Diagnostics/UpdateEntryEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Update;

namespace Microsoft.EntityFrameworkCore.Diagnostics
Expand All @@ -11,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics
/// A <see cref="DiagnosticSource" /> event payload class for events that have
/// an entity update entry.
/// </summary>
public class UpdateEntryEventData : EventData
public class UpdateEntryEventData : DbContextEventData
{
/// <summary>
/// Constructs the event payload.
Expand All @@ -23,7 +24,7 @@ public UpdateEntryEventData(
EventDefinitionBase eventDefinition,
Func<EventDefinitionBase, EventData, string> messageGenerator,
IUpdateEntry entityEntry)
: base(eventDefinition, messageGenerator)
: base(eventDefinition, messageGenerator, ((InternalEntityEntry)entityEntry).StateManager.Context)
{
EntityEntry = entityEntry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Cosmos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
Expand Down

0 comments on commit 27fa24d

Please sign in to comment.