Skip to content

Commit

Permalink
Fix up for .NET 6, fixes #108 (#109)
Browse files Browse the repository at this point in the history
* Fix up for .NET 6, fixes #108

* 1.0.5 is next logical version
  • Loading branch information
lol768 authored Dec 16, 2024
1 parent 3b13881 commit a3c4f83
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 27 deletions.
2 changes: 1 addition & 1 deletion EF.Extensions.PgCopy.Tests/DbContext/Blog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Blog
[Column("url")] public string Url { get; set; }

[Column("creation_datetime", TypeName = "timestamptz")]
public DateTime CreationDateTime { get; set; } = DateTime.Now;
public DateTime CreationDateTime { get; set; } = DateTime.UtcNow;

public List<Post> Posts { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion EF.Extensions.PgCopy.Tests/DbContext/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Post
[Column("online"), Required] public bool Online { get; set; }

[Column("creation_datetime", TypeName = "timestamptz")]
public DateTime CreationDateTime { get; set; } = DateTime.Now;
public DateTime CreationDateTime { get; set; } = DateTime.UtcNow;

public Blog Blog { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions EF.Extensions.PgCopy.Tests/EfCopyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ private static IEnumerable<Post> GeneratePosts(string title = "default title", l
{
Online = i % 2 == 0,
Content = $"Post some content {Guid.NewGuid().ToString()} into {title}-{i}",
PostDate = DateTime.Now,
PostDate = DateTime.UtcNow,
Title = $"{title}-{i}",
CreationDateTime = DateTime.Now
CreationDateTime = DateTime.UtcNow
};
}
}
Expand All @@ -112,7 +112,7 @@ private static IEnumerable<Blog> GenerateBlogs(string url = "default url", long
yield return new Blog
{
Url = $"https://{url}/{i}",
CreationDateTime = DateTime.Now
CreationDateTime = DateTime.UtcNow
};
}
}
Expand Down
7 changes: 4 additions & 3 deletions EF.Extensions.PgCopy/DbContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using MoreLinq;
using NeoSmart.AsyncLock;
using Npgsql;
using NpgsqlTypes;

Expand Down Expand Up @@ -159,7 +158,9 @@ private static object PostgreSqlCopyHelperFactory(IEntityType entityType)

var copyHelper = c.Invoke(new object[] {entityType.GetSchema(), QuoteIdentifier(entityType.GetTableName())});

var mapMethodInfo = copyHelper.GetType().GetMethod("Map", BindingFlags.Instance | BindingFlags.Public);
var mapMethodInfo = copyHelper.GetType().GetMethods().First(n =>
n.Name == "Map" && n.GetGenericArguments().Length == 1 && n.GetParameters().Length == 3 &&
n.GetParameters()[2].ParameterType == typeof(NpgsqlDbType));

var textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;

Expand Down
11 changes: 6 additions & 5 deletions EF.Extensions.PgCopy/EF.Extensions.PgCopy.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8</LangVersion>
<PackageId>EF.Extensions.PgCopy</PackageId>
<Version>1.0.0</Version>
<Version>1.0.5</Version>
<Authors>Fazzani</Authors>
<Company>Synker</Company>
<PackageProjectUrl>https://github.com/Fazzani/pg-efcore-copy</PackageProjectUrl>
Expand All @@ -20,10 +20,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
<PackageReference Include="morelinq" Version="3.3.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="PostgreSQLCopyHelper" Version="2.7.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
<PackageReference Include="PostgreSQLCopyHelper" Version="2.8.0" />
<PackageReference Include="NeoSmart.AsyncLock" Version="3.2.1" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions TestConsoleApp/Benchmarks/EfInsertBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;

Expand All @@ -13,6 +14,7 @@ public class EfInsertBenchmark
[Arguments(10_000)]
public void Save(long count)
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
var posts = EfInsertionTests.GeneratePosts(count: count == default ? 100 : count);
EfInsertionTests.Save(posts, false);
}
Expand All @@ -22,6 +24,7 @@ public void Save(long count)
[Arguments(10_000)]
public void SaveEfCopy(long count)
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
var posts = EfInsertionTests.GeneratePosts(count: count == default ? 100 : count);
EfInsertionTests.Save(posts);
}
Expand Down
17 changes: 17 additions & 0 deletions TestConsoleApp/BloggingContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using TestConsoleApp.DbContext;

namespace TestConsoleApp;

public class BloggingContextFactory : IDesignTimeDbContextFactory<BloggingContext>
{
public BloggingContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();
optionsBuilder.UseNpgsql(BloggingContext.ConnectionString, opt =>
opt.CommandTimeout((int) TimeSpan.FromMinutes(1).TotalSeconds));
return new BloggingContext(optionsBuilder.Options);
}
}
2 changes: 1 addition & 1 deletion TestConsoleApp/DbContext/Blog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Blog
[Column("url")] public string Url { get; set; }

[Column("creation_datetime", TypeName = "timestamptz")]
public DateTime CreationDateTime { get; set; } = DateTime.Now;
public DateTime CreationDateTime { get; set; } = DateTime.UtcNow;

public List<Post> Posts { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions TestConsoleApp/DbContext/BloggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TestConsoleApp.DbContext
{
public class BloggingContext : Microsoft.EntityFrameworkCore.DbContext
{
private const string ConnectionString = "Host=localhost;Port=54322;Database=dbtest;Username=db_user;Password=dtpass";
public const string ConnectionString = "Host=localhost;Port=54322;Database=dbtest;Username=db_user;Password=dtpass";

public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
Expand All @@ -15,7 +15,7 @@ public BloggingContext(DbContextOptions<BloggingContext> options)
{
}

public BloggingContext()
public BloggingContext() : base()
{

}
Expand Down
2 changes: 1 addition & 1 deletion TestConsoleApp/DbContext/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Post
[Column("online"), Required] public bool Online { get; set; }

[Column("creation_datetime", TypeName = "timestamptz")]
public DateTime CreationDateTime { get; set; } = DateTime.Now;
public DateTime CreationDateTime { get; set; } = DateTime.UtcNow;

public Blog Blog { get; set; }
}
Expand Down
6 changes: 3 additions & 3 deletions TestConsoleApp/EFInsertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public static IEnumerable<Post> GeneratePosts(string title = "default title", lo
Online = i % 2 == 0,
// BlogId = 1,
Content = $"Post some content {Guid.NewGuid().ToString()} into {title}-{i}",
PostDate = DateTime.Now,
PostDate = DateTime.UtcNow,
Title = $"{title}-{i}",
CreationDateTime = DateTime.Now
CreationDateTime = DateTime.UtcNow
};
}
}
Expand All @@ -36,7 +36,7 @@ public static IEnumerable<Blog> GenerateBlogs(string url = "default url", long c
yield return new Blog
{
Url = $"https://{url}/{i}",
CreationDateTime = DateTime.Now
CreationDateTime = DateTime.UtcNow
};
}
}
Expand Down
7 changes: 4 additions & 3 deletions TestConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class Program
/// <returns></returns>
static async Task Main(string[] args)
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

await TestEfInsertionExtenstionAsync(CancellationToken.None);
// await TestEfInsertion(CancellationToken.None);
// new EfInsertBenchmark().SaveEfCopy(100);
// var summary = BenchmarkRunner.Run(typeof(EfInsertBenchmark));
new EfInsertBenchmark().SaveEfCopy(100);
var summary = BenchmarkRunner.Run(typeof(EfInsertBenchmark));
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
Expand Down
10 changes: 7 additions & 3 deletions TestConsoleApp/TestConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.13.1" />
<PackageReference Include="EF.Extensions.PgCopy" Version="1.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9" />
<PackageReference Include="EF.Extensions.PgCopy" Version="1.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EF.Extensions.PgCopy\EF.Extensions.PgCopy.csproj" />
</ItemGroup>

</Project>

0 comments on commit a3c4f83

Please sign in to comment.