Skip to content

Commit

Permalink
Users/henkkin/update to net5 (#3)
Browse files Browse the repository at this point in the history
* Update to .net 5
  • Loading branch information
HenkKin authored Nov 11, 2020
1 parent 78b1a7d commit 74a8f04
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Moq.AutoMock" Version="1.2.0.120" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0-rc.2.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="Moq" Version="4.15.1" />
<PackageReference Include="Moq.AutoMock" Version="2.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void RemoveSoftDeletableProperties(SqlServerDbContext serverDbContext, E
var navigationPropertiesEntries = entityEntry.Navigations;
foreach (var navigationEntry in navigationPropertiesEntries)
{
if (navigationEntry.Metadata.IsCollection())
if (navigationEntry.Metadata.IsCollection)
{
if (navigationEntry.CurrentValue is ICollection collection)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
<PackageReleaseNotes></PackageReleaseNotes>
<Copyright>Henk Kin</Copyright>
<PackageTags>EntityFrameworkCore, EF, SqlServer, DependencyInjection, Multiple DbContext support, DataAccess, Repository, UnitOfWork, SoftDelete, Translation, Localization, RowVersioning, Multitenancy, Filtering, Paging, Sorting, Includes</PackageTags>
<Version>0.0.8</Version>
<Version>5.0.0</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityCloner.Microsoft.EntityFrameworkCore" Version="0.0.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="EntityCloner.Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" PrivateAssets="All" />
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="5.0.20" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.8.0-5.final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal static async Task<CriteriaResult<T>> ToCriteriaResultAsync<T>(this IQue
var options = ScriptOptions.Default.AddReferences(typeof(T).Assembly);

Expression<Func<T, bool>> whereClauseFunc =
CSharpScript.EvaluateAsync<Expression<Func<T, bool>>>(whereClause, options).Result;
await CSharpScript.EvaluateAsync<Expression<Func<T, bool>>>(whereClause, options);

source = source.Where(whereClauseFunc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

namespace DataAccessClient.EntityFrameworkCore.SqlServer
{
public abstract class SqlServerDbContext : DbContext, IDbContextPoolable
public abstract class SqlServerDbContext : DbContext, IResettableService
{
private static readonly MethodInfo DbContextResetStateMethodInfo;
private static readonly MethodInfo DbContextResetStateAsyncMethodInfo;
private static readonly MethodInfo DbContextResurrectMethodInfo;
internal static ConcurrentBag<Type> RegisteredDbContextTypes = new ConcurrentBag<Type>();
internal static ConcurrentDictionary<Type, List<Type>> RegisteredEntityTypesPerDbContexts = new ConcurrentDictionary<Type, List<Type>>();

Expand All @@ -31,9 +30,6 @@ static SqlServerDbContext()
DbContextResetStateAsyncMethodInfo = typeof(DbContext).GetMethod(
$"{typeof(IResettableService).FullName}.{nameof(IResettableService.ResetStateAsync)}",
BindingFlags.Instance | BindingFlags.NonPublic);
DbContextResurrectMethodInfo = typeof(DbContext).GetMethod(
$"{typeof(IDbContextPoolable).FullName}.{nameof(IDbContextPoolable.Resurrect)}",
BindingFlags.Instance | BindingFlags.NonPublic);
}

internal SqlServerDbContextExecutionContext ExecutionContext { get; private set; }
Expand All @@ -51,42 +47,11 @@ protected SqlServerDbContext(DbContextOptions options)
_dbContextResetStateAsyncMethod =
DbContextResetStateAsyncMethodInfo.CreateDelegate(typeof(Func<CancellationToken, Task>), this) as
Func<CancellationToken, Task>;
_dbContextResurrectMethod =
DbContextResurrectMethodInfo.CreateDelegate(typeof(Action<DbContextPoolConfigurationSnapshot>), this) as
Action<DbContextPoolConfigurationSnapshot>;

DataAccessClientOptionsExtension = options.FindExtension<DataAccessClientOptionsExtension>();
}

#region DbContextPooling

// https://stackoverflow.com/questions/37310896/overriding-explicit-interface-implementations

/// <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
/// 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>
void IDbContextPoolable.Resurrect(DbContextPoolConfigurationSnapshot configurationSnapshot)
{
if (_dbContextResurrectMethod != null)
{
_dbContextResurrectMethod.Invoke(configurationSnapshot);
}
else
{
throw new InvalidOperationException(
$"Cannot find method {nameof(IDbContextPoolable)}.{nameof(IDbContextPoolable.Resurrect)} on basetype DbContext of {GetType().FullName}");
}
}
#region IResettableService overrides to support DbContextPooling

/// <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
/// 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>
void IResettableService.ResetState()
{
ResetSqlServerDbContextState();
Expand All @@ -102,13 +67,6 @@ void IResettableService.ResetState()
}
}

/// <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
/// 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>
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
async Task IResettableService.ResetStateAsync(CancellationToken cancellationToken)
{
ResetSqlServerDbContextState();
Expand Down
18 changes: 9 additions & 9 deletions DataAccessClient.Tests/DataAccessClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0-rc.2.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="Moq" Version="4.15.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions DataAccessClient/DataAccessClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityCloner.Microsoft.EntityFrameworkCore" Version="0.0.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="EntityCloner.Microsoft.EntityFrameworkCore" Version="0.0.4" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" PrivateAssets="All" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions DataAccessClientExample/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task<IActionResult> DisableSoftDeletable()
OrderByDirection = OrderByDirection.Ascending,
Page = 1,
PageSize = 10,
Search = "Updated"
Search = "Henk"
};
criteria.Includes.Add("Translations");

Expand All @@ -181,7 +181,7 @@ public async Task<IActionResult> DisableSoftDeletable()
OrderByDirection = OrderByDirection.Ascending,
Page = 1,
PageSize = 10,
Search = "Updated"
Search = "Henk"
};

CriteriaResult<ExampleEntity> exampleEntitiesSearchResults;
Expand Down
8 changes: 3 additions & 5 deletions DataAccessClientExample/DataAccessClientExample.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-rc.2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.0-rc.2.*" />

</ItemGroup>

Expand All @@ -19,8 +19,6 @@

<ItemGroup>
<Folder Include="Migrations\" />
<Folder Include="Migrations\ExampleDatabase\" />
<Folder Include="Migrations\ExampleSecondDatabase\" />
</ItemGroup>

</Project>
12 changes: 1 addition & 11 deletions DataAccessClientExample/DataLayer/ExampleDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder
.Entity<ExampleEntityView>()
.HasNoKey()
.ToQuery(() =>
// TODO: Query does not work without query side evaluation, thows invalidoperationexception, needs investigation
(from exampleEntity in Set<ExampleEntity>()
from exampleEntityTranslation in Set<ExampleEntityTranslation>().Where(st => st.TranslatedEntityId == exampleEntity.Id)
select new ExampleEntityView
{
Id = exampleEntity.Id,
LocaleId = exampleEntityTranslation.LocaleId,
Name = exampleEntity.Name,
Description = exampleEntityTranslation.Description
}));
.ToSqlQuery("SELECT e.Id, et.LocaleId, e.Name, et.Description FROM dbo.ExampleEntities e INNER JOIN dbo.ExampleEntityTranslation et ON e.Id = et.TranslatedEntityId");

base.OnModelCreating(modelBuilder);
}
Expand Down
4 changes: 2 additions & 2 deletions DataAccessClientExample/DataLayer/Migrations.readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

cd [path-to-repository]\DataAccessClient\DataAccessClientExample

dotnet ef migrations Add [migrationname] --context ExampleDbContext --output-dir Migrations/ExampleDatabase
dotnet ef migrations Add [migrationname] --context ExampleSecondDbContext --output-dir Migrations/ExampleSecondDatabase
dotnet ef migrations Add Initial --context ExampleDbContext --output-dir Migrations/ExampleDatabase
dotnet ef migrations Add Initial --context ExampleSecondDbContext --output-dir Migrations/ExampleSecondDatabase

dotnet ef database update --context ExampleDbContext
dotnet ef database update --context ExampleSecondDbContext

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

Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "ExampleEntities",
columns: table => new
{
Id = table.Column<int>(nullable: false)
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CreatedOn = table.Column<DateTime>(nullable: false),
CreatedById = table.Column<int>(nullable: false),
ModifiedOn = table.Column<DateTime>(nullable: true),
ModifiedById = table.Column<int>(nullable: true),
IsDeleted = table.Column<bool>(nullable: false),
DeletedOn = table.Column<DateTime>(nullable: true),
DeletedById = table.Column<int>(nullable: true),
RowVersion = table.Column<byte[]>(rowVersion: true, nullable: true),
TenantId = table.Column<int>(nullable: false),
Name = table.Column<string>(nullable: true)
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
CreatedOn = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedById = table.Column<int>(type: "int", nullable: false),
ModifiedOn = table.Column<DateTime>(type: "datetime2", nullable: true),
ModifiedById = table.Column<int>(type: "int", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeletedOn = table.Column<DateTime>(type: "datetime2", nullable: true),
DeletedById = table.Column<int>(type: "int", nullable: true),
RowVersion = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: true),
TenantId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
Expand All @@ -33,9 +33,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "ExampleEntityTranslation",
columns: table => new
{
LocaleId = table.Column<string>(nullable: false),
TranslatedEntityId = table.Column<int>(nullable: false),
Description = table.Column<string>(nullable: true)
LocaleId = table.Column<string>(type: "nvarchar(450)", nullable: false),
TranslatedEntityId = table.Column<int>(type: "int", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
Expand Down
Loading

0 comments on commit 74a8f04

Please sign in to comment.