Skip to content

Commit 0a05611

Browse files
committed
updated to new ef core version
1 parent dc796ce commit 0a05611

File tree

92 files changed

+7199
-2629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+7199
-2629
lines changed

AspNetOAuth/AspNetOAuth.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.App" />
109
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" PrivateAssets="All" />
1110
</ItemGroup>
1211

Example/Data/Context.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.EntityFrameworkCore;
22
using Example.Data.Entities;
3-
using FileContextCore.Extensions;
3+
using FileContextCore;
44

55
namespace Example.Data
66
{
@@ -21,7 +21,7 @@ public class Context : DbContext
2121
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2222
{
2323
//Default: JSON-Serialize
24-
optionsBuilder.UseFileContext();
24+
optionsBuilder.UseFileContextDatabase("test");
2525

2626
//optionsBuilder.UseFileContext("bson");
2727

Example/Data/NewContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.EntityFrameworkCore;
22
using Example.Data.Entities;
3-
using FileContextCore.Extensions;
3+
using FileContextCore;
44

55
namespace Example.Data
66
{
@@ -21,7 +21,7 @@ public class NewContext : DbContext
2121
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2222
{
2323
//Default: JSON-Serialize
24-
optionsBuilder.UseFileContext(databasename: "new");
24+
optionsBuilder.UseFileContextDatabase("new");
2525

2626
//JSON-Serialize + simple Encryption
2727
//optionsBuilder.UseFileContext("json", "encrypted");

FileContextCore/Check.cs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) morrisjdev & .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Linq;
8-
using System.Reflection;
98
using JetBrains.Annotations;
10-
using Microsoft.EntityFrameworkCore.Internal;
9+
using Microsoft.EntityFrameworkCore.Diagnostics;
1110

1211
namespace FileContextCore.Utilities
1312
{
@@ -17,7 +16,9 @@ internal static class Check
1716
[ContractAnnotation("value:null => halt")]
1817
public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
1918
{
20-
if (value == null)
19+
#pragma warning disable IDE0041 // Use 'is null' check
20+
if (ReferenceEquals(value, null))
21+
#pragma warning restore IDE0041 // Use 'is null' check
2122
{
2223
NotEmpty(parameterName, nameof(parameterName));
2324

@@ -27,23 +28,6 @@ public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotN
2728
return value;
2829
}
2930

30-
[ContractAnnotation("value:null => halt")]
31-
public static T NotNull<T>(
32-
[NoEnumeration] T value,
33-
[InvokerParameterName] [NotNull] string parameterName,
34-
[NotNull] string propertyName)
35-
{
36-
if (value == null)
37-
{
38-
NotEmpty(parameterName, nameof(parameterName));
39-
NotEmpty(propertyName, nameof(propertyName));
40-
41-
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
42-
}
43-
44-
return value;
45-
}
46-
4731
[ContractAnnotation("value:null => halt")]
4832
public static IReadOnlyList<T> NotEmpty<T>(IReadOnlyList<T> value, [InvokerParameterName] [NotNull] string parameterName)
4933
{
@@ -53,7 +37,7 @@ public static IReadOnlyList<T> NotEmpty<T>(IReadOnlyList<T> value, [InvokerParam
5337
{
5438
NotEmpty(parameterName, nameof(parameterName));
5539

56-
throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
40+
throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(parameterName));
5741
}
5842

5943
return value;
@@ -63,13 +47,13 @@ public static IReadOnlyList<T> NotEmpty<T>(IReadOnlyList<T> value, [InvokerParam
6347
public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
6448
{
6549
Exception e = null;
66-
if (value == null)
50+
if (value is null)
6751
{
6852
e = new ArgumentNullException(parameterName);
6953
}
7054
else if (value.Trim().Length == 0)
7155
{
72-
e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
56+
e = new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName));
7357
}
7458

7559
if (e != null)
@@ -84,11 +68,12 @@ public static string NotEmpty(string value, [InvokerParameterName] [NotNull] str
8468

8569
public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
8670
{
87-
if (value != null && value.Length == 0)
71+
if (!(value is null)
72+
&& value.Length == 0)
8873
{
8974
NotEmpty(parameterName, nameof(parameterName));
9075

91-
throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
76+
throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName));
9277
}
9378

9479
return value;
@@ -109,16 +94,13 @@ public static IReadOnlyList<T> HasNoNulls<T>(IReadOnlyList<T> value, [InvokerPar
10994
return value;
11095
}
11196

112-
public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull] string parameterName)
97+
[Conditional("DEBUG")]
98+
public static void DebugAssert([System.Diagnostics.CodeAnalysis.DoesNotReturnIf(false)] bool condition, string message)
11399
{
114-
if (!value.GetTypeInfo().IsClass)
100+
if (!condition)
115101
{
116-
NotEmpty(parameterName, nameof(parameterName));
117-
118-
throw new ArgumentException(CoreStrings.InvalidEntityType(value));
102+
throw new Exception($"Check.DebugAssert failed: {message}");
119103
}
120-
121-
return value;
122104
}
123105
}
124106
}

FileContextCore/CodeAnnotations.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) morrisjdev & .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55

66
namespace JetBrains.Annotations
77
{
88
[AttributeUsage(
9-
AttributeTargets.Method | AttributeTargets.Parameter |
10-
AttributeTargets.Property | AttributeTargets.Delegate |
11-
AttributeTargets.Field)]
9+
AttributeTargets.Method
10+
| AttributeTargets.Parameter
11+
| AttributeTargets.Property
12+
| AttributeTargets.Delegate
13+
| AttributeTargets.Field)]
1214
internal sealed class NotNullAttribute : Attribute
1315
{
1416
}
1517

1618
[AttributeUsage(
17-
AttributeTargets.Method | AttributeTargets.Parameter |
18-
AttributeTargets.Property | AttributeTargets.Delegate |
19-
AttributeTargets.Field)]
19+
AttributeTargets.Method
20+
| AttributeTargets.Parameter
21+
| AttributeTargets.Property
22+
| AttributeTargets.Delegate
23+
| AttributeTargets.Field)]
2024
internal sealed class CanBeNullAttribute : Attribute
2125
{
2226
}
@@ -34,9 +38,9 @@ internal sealed class NoEnumerationAttribute : Attribute
3438
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
3539
internal sealed class ContractAnnotationAttribute : Attribute
3640
{
37-
public string Contract { get; private set; }
41+
public string Contract { get; }
3842

39-
public bool ForceFullStates { get; private set; }
43+
public bool ForceFullStates { get; }
4044

4145
public ContractAnnotationAttribute([NotNull] string contract)
4246
: this(contract, false)
@@ -75,20 +79,18 @@ public UsedImplicitlyAttribute(
7579
TargetFlags = targetFlags;
7680
}
7781

78-
public ImplicitUseKindFlags UseKindFlags { get; private set; }
79-
public ImplicitUseTargetFlags TargetFlags { get; private set; }
82+
public ImplicitUseKindFlags UseKindFlags { get; }
83+
public ImplicitUseTargetFlags TargetFlags { get; }
8084
}
8185

8286
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Delegate)]
8387
internal sealed class StringFormatMethodAttribute : Attribute
8488
{
8589
public StringFormatMethodAttribute([NotNull] string formatParameterName)
86-
{
87-
FormatParameterName = formatParameterName;
88-
}
90+
=> FormatParameterName = formatParameterName;
8991

9092
[NotNull]
91-
public string FormatParameterName { get; private set; }
93+
public string FormatParameterName { get; }
9294
}
9395

9496
[Flags]
Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) morrisjdev & .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
4+
using System.Diagnostics;
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.EntityFrameworkCore.Diagnostics;
77
using Microsoft.Extensions.Logging;
@@ -18,7 +18,7 @@ namespace FileContextCore.Diagnostics
1818
/// behavior of warnings.
1919
/// </para>
2020
/// </summary>
21-
static class FileContextEventId
21+
public static class FileContextEventId
2222
{
2323
// Warning: These values must not change between releases.
2424
// Only add new values to the end of sections, never in the middle.
@@ -33,11 +33,11 @@ private enum Id
3333
}
3434

3535
private static readonly string _transactionPrefix = DbLoggerCategory.Database.Transaction.Name + ".";
36-
private static EventId MakeTransactionId(Id id) => EventIdFactory.Create((int)id, _transactionPrefix + id);
36+
private static EventId MakeTransactionId(Id id) => new EventId((int)id, _transactionPrefix + id);
3737

3838
/// <summary>
3939
/// <para>
40-
/// Changes were saved to the database.
40+
/// A transaction operation was requested, but ignored because in-memory does not support transactions.
4141
/// </para>
4242
/// <para>
4343
/// This event is in the <see cref="DbLoggerCategory.Database.Transaction" /> category.
@@ -49,11 +49,11 @@ private enum Id
4949
public static readonly EventId TransactionIgnoredWarning = MakeTransactionId(Id.TransactionIgnoredWarning);
5050

5151
private static readonly string _updatePrefix = DbLoggerCategory.Update.Name + ".";
52-
private static EventId MakeUpdateId(Id id) => EventIdFactory.Create((int)id, _updatePrefix + id);
52+
private static EventId MakeUpdateId(Id id) => new EventId((int)id, _updatePrefix + id);
5353

5454
/// <summary>
5555
/// <para>
56-
/// A transaction operation was requested, but ignored because in-memory does not support transactions.
56+
/// Changes were saved to the database.
5757
/// </para>
5858
/// <para>
5959
/// This event is in the <see cref="DbLoggerCategory.Update" /> category.
@@ -63,36 +63,5 @@ private enum Id
6363
/// </para>
6464
/// </summary>
6565
public static readonly EventId ChangesSaved = MakeUpdateId(Id.ChangesSaved);
66-
67-
private static class EventIdFactory
68-
{
69-
public static EventId Create(int id, string name)
70-
{
71-
if (AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue9437", out bool isEnabled)
72-
&& isEnabled)
73-
{
74-
if (id >= CoreEventId.ProviderDesignBaseId)
75-
{
76-
id = MassageId(id, CoreEventId.ProviderDesignBaseId);
77-
}
78-
else if (id >= CoreEventId.ProviderBaseId)
79-
{
80-
id = MassageId(id, CoreEventId.ProviderBaseId);
81-
}
82-
else if (id >= CoreEventId.RelationalBaseId)
83-
{
84-
id = MassageId(id, CoreEventId.RelationalBaseId);
85-
}
86-
else if (id >= CoreEventId.CoreBaseId)
87-
{
88-
id = MassageId(id, CoreEventId.CoreBaseId);
89-
}
90-
}
91-
92-
return new EventId(id, name);
93-
}
94-
95-
private static int MassageId(int id, int baseId) => (id - baseId) + (baseId * 10);
96-
}
9766
}
9867
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) morrisjdev & .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using JetBrains.Annotations;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Diagnostics;
8+
using Microsoft.EntityFrameworkCore.Update;
9+
10+
// ReSharper disable once CheckNamespace
11+
namespace FileContextCore.Internal
12+
{
13+
/// <summary>
14+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
15+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
16+
/// any release. You should only use it directly in your code with extreme caution and knowing that
17+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
18+
/// </summary>
19+
public static class FileContextLoggerExtensions
20+
{
21+
/// <summary>
22+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
23+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
24+
/// any release. You should only use it directly in your code with extreme caution and knowing that
25+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
26+
/// </summary>
27+
public static void TransactionIgnoredWarning(
28+
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> diagnostics)
29+
{
30+
var definition = FileContextResources.LogTransactionsNotSupported(diagnostics);
31+
32+
var warningBehavior = definition.GetLogBehavior(diagnostics);
33+
if (warningBehavior != WarningBehavior.Ignore)
34+
{
35+
definition.Log(diagnostics, warningBehavior);
36+
}
37+
38+
if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
39+
{
40+
diagnostics.DiagnosticSource.Write(
41+
definition.EventId.Name,
42+
new EventData(
43+
definition,
44+
(d, _) => ((EventDefinition)d).GenerateMessage()));
45+
}
46+
}
47+
48+
/// <summary>
49+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
50+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
51+
/// any release. You should only use it directly in your code with extreme caution and knowing that
52+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
53+
/// </summary>
54+
public static void ChangesSaved(
55+
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Update> diagnostics,
56+
[NotNull] IEnumerable<IUpdateEntry> entries,
57+
int rowsAffected)
58+
{
59+
var definition = FileContextResources.LogSavedChanges(diagnostics);
60+
61+
var warningBehavior = definition.GetLogBehavior(diagnostics);
62+
if (warningBehavior != WarningBehavior.Ignore)
63+
{
64+
definition.Log(
65+
diagnostics,
66+
warningBehavior,
67+
rowsAffected);
68+
}
69+
70+
if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
71+
{
72+
diagnostics.DiagnosticSource.Write(
73+
definition.EventId.Name,
74+
new SaveChangesEventData(
75+
definition,
76+
ChangesSaved,
77+
entries,
78+
rowsAffected));
79+
}
80+
}
81+
82+
private static string ChangesSaved(EventDefinitionBase definition, EventData payload)
83+
{
84+
var d = (EventDefinition<int>)definition;
85+
var p = (SaveChangesEventData)payload;
86+
return d.GenerateMessage(p.RowsAffected);
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)