Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit c7f2c71

Browse files
authored
Merge pull request #148 from linq2db/version3
Release 3.11.0
2 parents e7078cf + 867de0d commit c7f2c71

Some content is hidden

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

44 files changed

+1050
-72
lines changed

Build/linq2db.Default.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.10.1</Version>
3+
<Version>3.11.0</Version>
44

55
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
66
<Product>Linq to DB</Product>

NuGet/linq2db.EntityFrameworkCore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<group targetFramework=".NETStandard2.0">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.10" />
19-
<dependency id="linq2db" version="3.3.0" />
19+
<dependency id="linq2db" version="3.4.0" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,25 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
150150
}
151151

152152
var isIdentity = prop.GetAnnotations()
153-
.Any(a => a.Name.EndsWith(":ValueGenerationStrategy") && a.Value?.ToString() == "IdentityColumn");
154-
155-
if (!isIdentity && isPrimaryKey)
156-
{
157-
isIdentity = prop.ValueGenerated == ValueGenerated.OnAdd;
158-
}
153+
.Any(a =>
154+
{
155+
if (a.Name.EndsWith(":ValueGenerationStrategy"))
156+
return a.Value?.ToString().Contains("Identity") == true;
157+
158+
if (a.Name.EndsWith(":Autoincrement"))
159+
return a.Value is bool b && b;
160+
161+
// for postgres
162+
if (a.Name == "Relational:DefaultValueSql")
163+
{
164+
if (a.Value is string str)
165+
{
166+
return str.ToLower().Contains("nextval");
167+
}
168+
}
169+
170+
return false;
171+
});
159172

160173
return new T[]{(T)(Attribute) new ColumnAttribute
161174
{

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.ContextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
233233
[LinqTunnel]
234234
[Pure]
235235
public static IValueInsertable<T> Into<T>(this DbContext context, ITable<T> target)
236-
where T: notnull
236+
where T: notnull
237237
{
238238
if (context == null) throw new ArgumentNullException(nameof(context));
239239
if (target == null) throw new ArgumentNullException(nameof(target));

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
using JetBrains.Annotations;
1919
using Microsoft.EntityFrameworkCore.Diagnostics;
20+
using Microsoft.Extensions.Caching.Memory;
2021

2122
namespace LinqToDB.EntityFrameworkCore
2223
{
@@ -84,10 +85,10 @@ public override int GetHashCode()
8485
#endregion
8586
}
8687

87-
readonly ConcurrentDictionary<ProviderKey, IDataProvider> _knownProviders = new ConcurrentDictionary<ProviderKey, IDataProvider>();
88+
readonly ConcurrentDictionary<ProviderKey, IDataProvider> _knownProviders = new();
8889

89-
private readonly MemoryCache _schemaCache = new MemoryCache(
90-
new MemoryCacheOptions
90+
private readonly MemoryCache _schemaCache = new(
91+
new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions
9192
{
9293
ExpirationScanFrequency = TimeSpan.FromHours(1.0)
9394
});

Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="linq2db" Version="3.3.0" />
26+
<PackageReference Include="linq2db" Version="3.4.0" />
2727
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.11" />
2828
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
2929
<PrivateAssets>all</PrivateAssets>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using FluentAssertions;
5+
using LinqToDB.Data;
6+
using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping;
7+
using NUnit.Framework;
8+
9+
namespace LinqToDB.EntityFrameworkCore.BaseTests
10+
{
11+
public abstract class ForMappingTestsBase : TestsBase
12+
{
13+
public abstract ForMappingContextBase CreateContext();
14+
15+
[Test]
16+
public virtual void TestIdentityMapping()
17+
{
18+
using var context = CreateContext();
19+
using var connection = context.CreateLinqToDbConnection();
20+
21+
var ed = connection.MappingSchema.GetEntityDescriptor(typeof(WithIdentity));
22+
var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single();
23+
24+
pk.IsIdentity.Should().BeTrue();
25+
}
26+
27+
[Test]
28+
public virtual void TestNoIdentityMapping()
29+
{
30+
using var context = CreateContext();
31+
using var connection = context.CreateLinqToDbConnection();
32+
33+
var ed = connection.MappingSchema.GetEntityDescriptor(typeof(NoIdentity));
34+
var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single();
35+
36+
pk.IsIdentity.Should().BeFalse();
37+
}
38+
39+
[Test]
40+
public virtual void TestTableCreation()
41+
{
42+
using var context = CreateContext();
43+
using var connection = context.CreateLinqToDbConnection();
44+
45+
using var t1 = connection.CreateTempTable<WithIdentity>();
46+
using var t2 = connection.CreateTempTable<NoIdentity>();
47+
}
48+
49+
50+
[Test]
51+
public virtual void TestBulkCopyNoIdentity()
52+
{
53+
using var context = CreateContext();
54+
using var connection = context.CreateLinqToDbConnection();
55+
56+
using var t = connection.CreateTempTable<NoIdentity>();
57+
58+
var items = new List<NoIdentity>()
59+
{
60+
new() {Id = Guid.NewGuid(), Name = "John Doe"},
61+
new() {Id = Guid.NewGuid(), Name = "Jane Doe"}
62+
};
63+
64+
t.BulkCopy(items);
65+
66+
67+
items.Should().BeEquivalentTo(t);
68+
}
69+
70+
[Test]
71+
public virtual void TestBulkCopyWithIdentity()
72+
{
73+
using var context = CreateContext();
74+
using var connection = context.CreateLinqToDbConnection();
75+
76+
using var t = connection.CreateTempTable<WithIdentity>();
77+
78+
var items = new List<WithIdentity>()
79+
{
80+
new() {Id = 1, Name = "John Doe"},
81+
new() {Id = 2, Name = "Jane Doe"}
82+
};
83+
84+
t.BulkCopy(items);
85+
86+
87+
t.Should().HaveCount(items.Count);
88+
}
89+
90+
}
91+
}

Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="FluentAssertions" Version="5.10.3" />
1213
<PackageReference Include="linq2db.Tools" Version="3.2.3" />
1314
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
1415
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.11" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping
4+
{
5+
public abstract class ForMappingContextBase : DbContext
6+
{
7+
protected ForMappingContextBase(DbContextOptions options) : base(options)
8+
{
9+
}
10+
11+
public DbSet<WithIdentity> WithIdentity { get; set; } = null!;
12+
public DbSet<NoIdentity> NoIdentity { get; set; } = null!;
13+
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping
4+
{
5+
public class NoIdentity
6+
{
7+
public Guid Id { get; set; }
8+
public string Name { get; set; } = null!;
9+
}
10+
}

0 commit comments

Comments
 (0)