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

Commit c43460c

Browse files
authored
Merge pull request #161 from linq2db/master
Release 5.4.0
2 parents 24fc948 + 83f0d85 commit c43460c

File tree

18 files changed

+224
-36
lines changed

18 files changed

+224
-36
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>5.3.1</Version>
3+
<Version>5.4.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.1">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="5.0.2" />
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: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Concurrent;
34
using System.Collections.Generic;
5+
using System.Data;
46
using System.Linq;
57
using System.Linq.Expressions;
68
using System.Reflection;
@@ -135,6 +137,41 @@ static bool CompareProperty(IProperty property, MemberInfo memberInfo)
135137
{
136138
return CompareProperty(property.GetIdentifyingMemberInfo(), memberInfo);
137139
}
140+
141+
static DataType DbTypeToDataType(DbType dbType)
142+
{
143+
return dbType switch
144+
{
145+
DbType.AnsiString => DataType.VarChar,
146+
DbType.AnsiStringFixedLength => DataType.VarChar,
147+
DbType.Binary => DataType.Binary,
148+
DbType.Boolean => DataType.Boolean,
149+
DbType.Byte => DataType.Byte,
150+
DbType.Currency => DataType.Money,
151+
DbType.Date => DataType.Date,
152+
DbType.DateTime => DataType.DateTime,
153+
DbType.DateTime2 => DataType.DateTime2,
154+
DbType.DateTimeOffset => DataType.DateTimeOffset,
155+
DbType.Decimal => DataType.Decimal,
156+
DbType.Double => DataType.Double,
157+
DbType.Guid => DataType.Guid,
158+
DbType.Int16 => DataType.Int16,
159+
DbType.Int32 => DataType.Int32,
160+
DbType.Int64 => DataType.Int64,
161+
DbType.Object => DataType.Undefined,
162+
DbType.SByte => DataType.SByte,
163+
DbType.Single => DataType.Single,
164+
DbType.String => DataType.NVarChar,
165+
DbType.StringFixedLength => DataType.NVarChar,
166+
DbType.Time => DataType.Time,
167+
DbType.UInt16 => DataType.UInt16,
168+
DbType.UInt32 => DataType.UInt32,
169+
DbType.UInt64 => DataType.UInt64,
170+
DbType.VarNumeric => DataType.VarNumeric,
171+
DbType.Xml => DataType.Xml,
172+
_ => DataType.Undefined
173+
};
174+
}
138175

139176
public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = true) where T : Attribute
140177
{
@@ -191,16 +228,34 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
191228
return false;
192229
});
193230

194-
return new T[]{(T)(Attribute) new ColumnAttribute
231+
var dataType = DataType.Undefined;
232+
233+
if (prop.GetTypeMapping() is RelationalTypeMapping typeMapping)
195234
{
196-
Name = prop.GetColumnName(storeObjectId!.Value),
197-
Length = prop.GetMaxLength() ?? 0,
198-
CanBeNull = prop.IsNullable,
199-
DbType = prop.GetColumnType(),
200-
IsPrimaryKey = isPrimaryKey,
201-
PrimaryKeyOrder = primaryKeyOrder,
202-
IsIdentity = isIdentity,
203-
}};
235+
if (typeMapping.DbType != null)
236+
{
237+
dataType = DbTypeToDataType(typeMapping.DbType.Value);
238+
}
239+
else
240+
{
241+
dataType = SqlDataType.GetDataType(typeMapping.ClrType).Type.DataType;
242+
}
243+
}
244+
245+
return new T[]
246+
{
247+
(T)(Attribute)new ColumnAttribute
248+
{
249+
Name = prop.GetColumnName(storeObjectId!.Value),
250+
Length = prop.GetMaxLength() ?? 0,
251+
CanBeNull = prop.IsNullable,
252+
DbType = prop.GetColumnType(),
253+
DataType = dataType,
254+
IsPrimaryKey = isPrimaryKey,
255+
PrimaryKeyOrder = primaryKeyOrder,
256+
IsIdentity = isIdentity,
257+
}
258+
};
204259
}
205260
}
206261

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

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

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

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

561+
static readonly MethodInfo TagWithMethodInfo =
562+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagWith(string.Empty));
563+
561564
static readonly MethodInfo ThenIncludeEnumerableMethodInfo =
562565
MemberHelper.MethodOfGeneric<IIncludableQueryable<object, IEnumerable<object>>>(q => q.ThenInclude<object, object, object>(null));
563566

@@ -580,6 +583,9 @@ static readonly MethodInfo
580583

581584
static readonly MethodInfo ToSql = MemberHelper.MethodOfGeneric(() => Sql.ToSql(1));
582585

586+
static readonly MethodInfo TagQueryMethodInfo =
587+
MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.TagQuery(string.Empty));
588+
583589
/// <summary>
584590
/// Removes conversions from expression.
585591
/// </summary>
@@ -871,6 +877,14 @@ TransformInfo LocalTransform(Expression e)
871877
// it is only one possible way now how to detect nested query.
872878
ignoreTracking = true;
873879
}
880+
else if (generic == TagWithMethodInfo)
881+
{
882+
var method =
883+
TagQueryMethodInfo.MakeGenericMethod(methodCall.Method.GetGenericArguments());
884+
885+
return new TransformInfo(Expression.Call(method, methodCall.Arguments.Select(a => a.Transform(l => LocalTransform(l)))
886+
.ToArray()), false, true);
887+
}
874888

875889
if (isTunnel)
876890
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="5.0.2" />
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.1.6" />
13+
<PackageReference Include="linq2db.Tools" Version="3.4.2" />
1414
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
1515
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
1616
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />

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)