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

Commit a8b15bc

Browse files
authored
Merge pull request #162 from linq2db/version3
Release 3.12.0
2 parents 227b93c + 10da369 commit a8b15bc

File tree

18 files changed

+222
-39
lines changed

18 files changed

+222
-39
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.11.1</Version>
3+
<Version>3.12.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.4.0" />
19+
<dependency id="linq2db" version="3.4.2" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4+
using System.Data;
45
using System.Linq;
56
using System.Linq.Expressions;
67
using System.Reflection;
@@ -132,6 +133,41 @@ static bool CompareProperty(IProperty property, MemberInfo memberInfo)
132133
{
133134
return CompareProperty(property.GetIdentifyingMemberInfo(), memberInfo);
134135
}
136+
137+
static DataType DbTypeToDataType(DbType dbType)
138+
{
139+
return dbType switch
140+
{
141+
DbType.AnsiString => DataType.VarChar,
142+
DbType.AnsiStringFixedLength => DataType.VarChar,
143+
DbType.Binary => DataType.Binary,
144+
DbType.Boolean => DataType.Boolean,
145+
DbType.Byte => DataType.Byte,
146+
DbType.Currency => DataType.Money,
147+
DbType.Date => DataType.Date,
148+
DbType.DateTime => DataType.DateTime,
149+
DbType.DateTime2 => DataType.DateTime2,
150+
DbType.DateTimeOffset => DataType.DateTimeOffset,
151+
DbType.Decimal => DataType.Decimal,
152+
DbType.Double => DataType.Double,
153+
DbType.Guid => DataType.Guid,
154+
DbType.Int16 => DataType.Int16,
155+
DbType.Int32 => DataType.Int32,
156+
DbType.Int64 => DataType.Int64,
157+
DbType.Object => DataType.Undefined,
158+
DbType.SByte => DataType.SByte,
159+
DbType.Single => DataType.Single,
160+
DbType.String => DataType.NVarChar,
161+
DbType.StringFixedLength => DataType.NVarChar,
162+
DbType.Time => DataType.Time,
163+
DbType.UInt16 => DataType.UInt16,
164+
DbType.UInt32 => DataType.UInt32,
165+
DbType.UInt64 => DataType.UInt64,
166+
DbType.VarNumeric => DataType.VarNumeric,
167+
DbType.Xml => DataType.Xml,
168+
_ => DataType.Undefined
169+
};
170+
}
135171

136172
public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = true) where T : Attribute
137173
{
@@ -184,16 +220,34 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
184220
return false;
185221
});
186222

187-
return new T[]{(T)(Attribute) new ColumnAttribute
223+
var dataType = DataType.Undefined;
224+
225+
if (prop.GetTypeMapping() is RelationalTypeMapping typeMapping)
226+
{
227+
if (typeMapping.DbType != null)
228+
{
229+
dataType = DbTypeToDataType(typeMapping.DbType.Value);
230+
}
231+
else
232+
{
233+
dataType = SqlDataType.GetDataType(typeMapping.ClrType).Type.DataType;
234+
}
235+
}
236+
237+
return new T[]
188238
{
189-
Name = prop.GetColumnName(),
190-
Length = prop.GetMaxLength() ?? 0,
191-
CanBeNull = prop.IsNullable,
192-
DbType = prop.GetColumnType(),
193-
IsPrimaryKey = isPrimaryKey,
194-
PrimaryKeyOrder = primaryKeyOrder,
195-
IsIdentity = isIdentity,
196-
}};
239+
(T)(Attribute)new ColumnAttribute
240+
{
241+
Name = prop.GetColumnName(),
242+
Length = prop.GetMaxLength() ?? 0,
243+
CanBeNull = prop.IsNullable,
244+
DbType = prop.GetColumnType(),
245+
DataType = dataType,
246+
IsPrimaryKey = isPrimaryKey,
247+
PrimaryKeyOrder = primaryKeyOrder,
248+
IsIdentity = isIdentity,
249+
}
250+
};
197251
}
198252
}
199253

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,14 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToke
162162
{
163163
return QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
164164
}
165+
166+
/// <summary>
167+
/// Returns generated SQL for specific LINQ query.
168+
/// </summary>
169+
/// <returns>Generated SQL.</returns>
170+
public override string ToString()
171+
{
172+
return QueryProvider.ToString();
173+
}
165174
}
166175
}

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ public virtual MappingSchema GetMappingSchema(
563563
static readonly MethodInfo ThenIncludeMethodInfo =
564564
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, object>>(q => q.ThenInclude<object, object, object>(null));
565565

566+
static readonly MethodInfo TagWithMethodInfo =
567+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagWith(string.Empty));
568+
566569
static readonly MethodInfo ThenIncludeEnumerableMethodInfo =
567570
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, IEnumerable<object>>>(q => q.ThenInclude<object, object, object>(null));
568571

@@ -585,6 +588,9 @@ static readonly MethodInfo
585588

586589
static readonly MethodInfo ToSql = MemberHelper.MethodOfGeneric(() => Sql.ToSql(1));
587590

591+
static readonly MethodInfo TagQueryMethodInfo =
592+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagQuery(string.Empty));
593+
588594
/// <summary>
589595
/// Removes conversions from expression.
590596
/// </summary>
@@ -876,6 +882,14 @@ TransformInfo LocalTransform(Expression e)
876882
// it is only one possible way now how to detect nested query.
877883
ignoreTracking = true;
878884
}
885+
else if (generic == TagWithMethodInfo)
886+
{
887+
var method =
888+
TagQueryMethodInfo.MakeGenericMethod(methodCall.Method.GetGenericArguments());
889+
890+
return new TransformInfo(Expression.Call(method, methodCall.Arguments.Select(a => a.Transform(l => LocalTransform(l)))
891+
.ToArray()), false, true);
892+
}
879893

880894
if (isTunnel)
881895
return new TransformInfo(methodCall.Arguments[0], false, true);

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.4.0" />
26+
<PackageReference Include="linq2db" Version="3.4.2" />
2727
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.11" />
2828
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
2929
<PrivateAssets>all</PrivateAssets>

Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Threading.Tasks;
45
using FluentAssertions;
56
using LinqToDB.Data;
67
using LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping;
@@ -87,5 +88,25 @@ public virtual void TestBulkCopyWithIdentity()
8788
t.Should().HaveCount(items.Count);
8889
}
8990

91+
[Test]
92+
public virtual async Task TestUIntTable()
93+
{
94+
using var context = CreateContext();
95+
context.UIntTable.Add(new UIntTable
96+
{
97+
Field16 = 1,
98+
Field16N = 2,
99+
Field32 = 3,
100+
Field32N = 4,
101+
Field64 = 5,
102+
Field64N = 6
103+
});
104+
105+
await context.SaveChangesAsync();
106+
107+
ulong field64 = 5;
108+
var item = await context.UIntTable.FirstOrDefaultAsyncLinqToDB(e => e.Field64 == field64);
109+
}
110+
90111
}
91112
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="FluentAssertions" Version="5.10.3" />
13-
<PackageReference Include="linq2db.Tools" Version="3.2.3" />
13+
<PackageReference Include="linq2db.Tools" Version="3.4.2" />
1414
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
1515
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.11" />
1616
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.11" />

Tests/LinqToDB.EntityFrameworkCore.BaseTests/Models/ForMapping/ForMappingContextBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ protected ForMappingContextBase(DbContextOptions options) : base(options)
1010

1111
public DbSet<WithIdentity> WithIdentity { get; set; } = null!;
1212
public DbSet<NoIdentity> NoIdentity { get; set; } = null!;
13-
13+
public DbSet<UIntTable> UIntTable { get; set; } = null!;
14+
public DbSet<StringTypes> StringTypes { get; set; } = null!;
1415
}
1516
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping
4+
{
5+
public class StringTypes
6+
{
7+
[Key]
8+
public int Id { get; set; }
9+
10+
public string? AnsiString { get; set; }
11+
12+
public string? UnicodeString { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)