Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable internal code usage analyzer on the providers #20567

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/EFCore.Cosmos/EFCore.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<ProjectReference Include="..\EFCore\EFCore.csproj" PrivateAssets="contentfiles;build" />
<ProjectReference Condition="'$(BuildingByReSharper)' != 'true'" Include="..\EFCore.Analyzers\EFCore.Analyzers.csproj" ReferenceOutputAssembly="False" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,12 @@ private void AddInclude(
var includeMethod = navigation.IsCollection ? _includeCollectionMethodInfo : _includeReferenceMethodInfo;
var includingClrType = navigation.DeclaringEntityType.ClrType;
var relatedEntityClrType = navigation.TargetEntityType.ClrType;
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var entityEntryVariable = _trackQueryResults
? shaperBlock.Variables.Single(v => v.Type == typeof(InternalEntityEntry))
: (Expression)Expression.Constant(null, typeof(InternalEntityEntry));
#pragma warning restore EF1001 // Internal EF Core API usage.
var concreteEntityTypeVariable = shaperBlock.Variables.Single(v => v.Type == typeof(IEntityType));
var inverseNavigation = navigation.Inverse;
var fixup = GenerateFixup(
Expand All @@ -394,7 +397,10 @@ private static readonly MethodInfo _includeReferenceMethodInfo
.GetDeclaredMethod(nameof(IncludeReference));

private static void IncludeReference<TIncludingEntity, TIncludedEntity>(
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
InternalEntityEntry entry,
#pragma warning restore EF1001 // Internal EF Core API usage.
object entity,
IEntityType entityType,
TIncludedEntity relatedEntity,
Expand Down Expand Up @@ -426,7 +432,10 @@ private static void IncludeReference<TIncludingEntity, TIncludedEntity>(
// For non-null relatedEntity StateManager will set the flag
else if (relatedEntity == null)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
entry.SetIsLoaded(navigation);
#pragma warning restore EF1001 // Internal EF Core API usage.
}
}

Expand All @@ -435,7 +444,10 @@ private static readonly MethodInfo _includeCollectionMethodInfo
.GetDeclaredMethod(nameof(IncludeCollection));

private static void IncludeCollection<TIncludingEntity, TIncludedEntity>(
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
InternalEntityEntry entry,
#pragma warning restore EF1001 // Internal EF Core API usage.
object entity,
IEntityType entityType,
IEnumerable<TIncludedEntity> relatedEntities,
Expand Down Expand Up @@ -473,7 +485,10 @@ private static void IncludeCollection<TIncludingEntity, TIncludedEntity>(
}
else
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
entry.SetIsLoaded(navigation);
#pragma warning restore EF1001 // Internal EF Core API usage.
if (relatedEntities != null)
{
using var enumerator = relatedEntities.GetEnumerator();
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,18 @@ public override int SaveChanges(IList<IUpdateEntry> entries)

if (!entityType.IsDocumentRoot())
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var root = GetRootDocument((InternalEntityEntry)entry);
#pragma warning restore EF1001 // Internal EF Core API usage.
if (!entriesSaved.Contains(root)
&& rootEntriesToSave.Add(root)
&& root.EntityState == EntityState.Unchanged)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
((InternalEntityEntry)root).SetEntityState(EntityState.Modified);
#pragma warning restore EF1001 // Internal EF Core API usage.
}

continue;
Expand Down Expand Up @@ -154,7 +160,10 @@ public override async Task<int> SaveChangesAsync(
&& rootEntriesToSave.Add(root)
&& root.EntityState == EntityState.Unchanged)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
((InternalEntityEntry)root).SetEntityState(EntityState.Modified);
#pragma warning restore EF1001 // Internal EF Core API usage.
}

continue;
Expand Down Expand Up @@ -325,6 +334,8 @@ public virtual DocumentSource GetDocumentSource([NotNull] IEntityType entityType
return documentSource;
}

#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
private IUpdateEntry GetRootDocument(InternalEntityEntry entry)
{
var stateManager = entry.StateManager;
Expand All @@ -349,6 +360,7 @@ private IUpdateEntry GetRootDocument(InternalEntityEntry entry)

return principal.EntityType.IsDocumentRoot() ? principal : GetRootDocument(principal);
}
#pragma warning restore EF1001 // Internal EF Core API usage.

private Exception ThrowUpdateException(CosmosException exception, IUpdateEntry entry)
{
Expand Down
23 changes: 22 additions & 1 deletion src/EFCore.Cosmos/Update/Internal/DocumentSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,23 @@ public virtual JObject CreateDocument([NotNull] IUpdateEntry entry, int? ordinal
}
else if (fk.IsUnique)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType);
document[embeddedPropertyName] = _database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry);
#pragma warning restore EF1001 // Internal EF Core API usage.
}
else
{
var embeddedOrdinal = 0;
var array = new JArray();
foreach (var dependent in (IEnumerable)embeddedValue)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType);
array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry, embeddedOrdinal));
#pragma warning restore EF1001 // Internal EF Core API usage.
embeddedOrdinal++;
}

Expand All @@ -141,7 +147,7 @@ public virtual JObject CreateDocument([NotNull] IUpdateEntry entry, int? ordinal
/// </summary>
public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpdateEntry entry)
=> UpdateDocument(document, entry, null);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand All @@ -151,7 +157,10 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd
public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpdateEntry entry, int? ordinal)
{
var anyPropertyUpdated = false;
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var stateManager = ((InternalEntityEntry)entry).StateManager;
#pragma warning restore EF1001 // Internal EF Core API usage.
foreach (var property in entry.EntityType.GetProperties())
{
if (entry.EntityState == EntityState.Added
Expand Down Expand Up @@ -196,7 +205,10 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd
}
else if (fk.IsUnique)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType);
#pragma warning restore EF1001 // Internal EF Core API usage.
if (embeddedEntry == null)
{
continue;
Expand All @@ -222,6 +234,8 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd
var shouldSetTemporaryKeys = false;
foreach (var dependent in (IEnumerable)embeddedValue)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var embeddedEntry = stateManager.TryGetEntry(dependent, fk.DeclaringEntityType);
if (embeddedEntry == null)
{
Expand All @@ -233,6 +247,7 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd
shouldSetTemporaryKeys = true;
break;
}
#pragma warning restore EF1001 // Internal EF Core API usage.

embeddedOrdinal++;
}
Expand All @@ -242,13 +257,16 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd
var temporaryOrdinal = -1;
foreach (var dependent in (IEnumerable)embeddedValue)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var embeddedEntry = stateManager.TryGetEntry(dependent, fk.DeclaringEntityType);
if (embeddedEntry == null)
{
continue;
}

embeddedEntry.SetTemporaryValue(ordinalKeyProperty, temporaryOrdinal, setModified: false);
#pragma warning restore EF1001 // Internal EF Core API usage.

temporaryOrdinal--;
}
Expand All @@ -259,7 +277,10 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd
var array = new JArray();
foreach (var dependent in (IEnumerable)embeddedValue)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
// #16707
var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType);
#pragma warning restore EF1001 // Internal EF Core API usage.
if (embeddedEntry == null)
{
continue;
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.InMemory/EFCore.InMemory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<ProjectReference Include="..\EFCore\EFCore.csproj" PrivateAssets="contentfiles;build" />
<ProjectReference Condition="'$(BuildingByReSharper)' != 'true'" Include="..\EFCore.Analyzers\EFCore.Analyzers.csproj" ReferenceOutputAssembly="False" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ private static (Expression, Expression) DecomposeJoinCondition(Expression joinCo

static Expression CreateAnonymousObject(List<Expression> expressions)
=> Expression.New(
#pragma warning disable EF1001 // Internal EF Core API usage.
// #20565
AnonymousObject.AnonymousObjectCtor,
#pragma warning restore EF1001 // Internal EF Core API usage.
Expression.NewArrayInit(
typeof(object),
expressions.Select(e => Expression.Convert(e, typeof(object)))));
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Proxies/EFCore.Proxies.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="..\EFCore\EFCore.csproj" PrivateAssets="contentfiles;build" />
<ProjectReference Condition="'$(BuildingByReSharper)' != 'true'" Include="..\EFCore.Analyzers\EFCore.Analyzers.csproj" ReferenceOutputAssembly="False" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Proxies.Internal
{
Expand Down Expand Up @@ -70,7 +69,8 @@ public virtual void Intercept(IInvocation invocation)
var property = _entityType.FindProperty(propertyName);
if (property != null)
{
var comparer = property.IsKeyOrForeignKey()
var comparer = property.IsKey()
|| property.IsForeignKey()
? property.GetKeyValueComparer()
: property.GetValueComparer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Proxies.Internal
{
Expand Down Expand Up @@ -70,7 +69,8 @@ public virtual void Intercept(IInvocation invocation)
var property = _entityType.FindProperty(propertyName);
if (property != null)
{
var comparer = property.IsKeyOrForeignKey()
var comparer = property.IsKey()
|| property.IsForeignKey()
? property.GetKeyValueComparer()
: property.GetValueComparer();

Expand Down
8 changes: 8 additions & 0 deletions src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,
var proxyType = _proxyFactory.CreateProxyType(_options, entityType);

// WARNING: This code is EF internal; it should not be copied. See #10789 #14554
#pragma warning disable EF1001 // Internal EF Core API usage.
var binding = (InstantiationBinding)entityType[CoreAnnotationNames.ConstructorBinding];
#pragma warning restore EF1001 // Internal EF Core API usage.
if (binding == null)
{
_directBindingConvention.ProcessModelFinalizing(modelBuilder, context);
}

// WARNING: This code is EF internal; it should not be copied. See #10789 #14554
#pragma warning disable EF1001 // Internal EF Core API usage.
binding = (InstantiationBinding)entityType[CoreAnnotationNames.ConstructorBinding];
#pragma warning restore EF1001 // Internal EF Core API usage.

if (_options.UseLazyLoadingProxies)
{
Expand All @@ -106,7 +110,9 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,

entityType.SetAnnotation(
// WARNING: This code is EF internal; it should not be copied. See #10789 #14554
#pragma warning disable EF1001 // Internal EF Core API usage.
CoreAnnotationNames.ConstructorBinding,
#pragma warning restore EF1001 // Internal EF Core API usage.
new FactoryMethodBinding(
_proxyFactory,
_createLazyLoadingProxyMethod,
Expand All @@ -123,7 +129,9 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,
{
entityType.SetAnnotation(
// WARNING: This code is EF internal; it should not be copied. See #10789 #14554
#pragma warning disable EF1001 // Internal EF Core API usage.
CoreAnnotationNames.ConstructorBinding,
#pragma warning restore EF1001 // Internal EF Core API usage.
new FactoryMethodBinding(
_proxyFactory,
_createProxyMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder
if (_options?.UseChangeTrackingProxies == true)
{
modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotifications);
#pragma warning disable EF1001 // Internal EF Core API usage.
modelBuilder.HasAnnotation(CoreAnnotationNames.SkipChangeTrackingStrategyValidationAnnotation, "true");
#pragma warning restore EF1001 // Internal EF Core API usage.
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/EFCore.Relational.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\EFCore\EFCore.csproj" PrivateAssets="contentfiles;build" />
<ProjectReference Condition="'$(DisableEFAnalyzer)' != 'true'" Include="..\EFCore.Analyzers\EFCore.Analyzers.csproj" ReferenceOutputAssembly="False" OutputItemType="Analyzer" />
<ProjectReference Condition="'$(BuildingByReSharper)' != 'true'" Include="..\EFCore.Analyzers\EFCore.Analyzers.csproj" ReferenceOutputAssembly="False" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions src/EFCore.Relational/Query/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
Expand All @@ -10,6 +11,11 @@ namespace Microsoft.EntityFrameworkCore.Query
{
public static class ExpressionExtensions
{
public static bool IsLogicalNot([NotNull] this SqlUnaryExpression sqlUnaryExpression)
=> sqlUnaryExpression.OperatorType == ExpressionType.Not
&& (sqlUnaryExpression.Type == typeof(bool)
|| sqlUnaryExpression.Type == typeof(bool?));

public static RelationalTypeMapping InferTypeMapping([NotNull] params SqlExpression[] expressions)
{
Check.NotNull(expressions, nameof(expressions));
Expand Down
Loading