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

Commit 64c3fdb

Browse files
authored
Merge pull request #97 from linq2db/master
Release 5.1.1
2 parents 65022b4 + ee77d5d commit 64c3fdb

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public LinqToDBForEFToolsDataConnection(
5858
Context = context;
5959
_model = model;
6060
_transformFunc = transformFunc;
61+
CopyDatabaseProperties();
6162
if (LinqToDBForEFTools.EnableChangeTracker)
6263
OnEntityCreated += OnEntityCreatedHandler;
6364
}
@@ -81,6 +82,7 @@ public LinqToDBForEFToolsDataConnection(
8182
Context = context;
8283
_model = model;
8384
_transformFunc = transformFunc;
85+
CopyDatabaseProperties();
8486
if (LinqToDBForEFTools.EnableChangeTracker)
8587
OnEntityCreated += OnEntityCreatedHandler;
8688
}
@@ -103,6 +105,7 @@ public LinqToDBForEFToolsDataConnection(
103105
Context = context;
104106
_model = model;
105107
_transformFunc = transformFunc;
108+
CopyDatabaseProperties();
106109
if (LinqToDBForEFTools.EnableChangeTracker)
107110
OnEntityCreated += OnEntityCreatedHandler;
108111
}
@@ -169,5 +172,11 @@ private void OnEntityCreatedHandler(EntityCreatedEventArgs args)
169172
args.Entity = entry.Entity;
170173
}
171174

175+
private void CopyDatabaseProperties()
176+
{
177+
var commandTimeout = Context?.Database.GetCommandTimeout();
178+
if (commandTimeout != null)
179+
CommandTimeout = commandTimeout.Value;
180+
}
172181
}
173182
}

Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Models/Northwind/NorthwindContext.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System;
2+
using System.Reflection;
23
using LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind;
34
using LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.Northwind.Mapping;
45
using LinqToDB.Expressions;
@@ -28,6 +29,12 @@ public NorthwindContext(DbContextOptions options) : base(options)
2829

2930
}
3031

32+
[DbFunction("ProcessLong", "dbo")]
33+
public static int ProcessLong(int seconds)
34+
{
35+
throw new NotImplementedException();
36+
}
37+
3138
protected override void OnModelCreating(ModelBuilder builder)
3239
{
3340
builder.ApplyConfiguration(new CategoriesMap());

Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,5 +774,50 @@ public void TestNullability([Values(true, false)] bool enableFilter)
774774
}
775775

776776

777+
[Test]
778+
public void TestCommandTimeout()
779+
{
780+
int timeoutErrorCode = -2; // Timeout Expired
781+
int commandTimeout = 1;
782+
int commandExecutionTime = 5;
783+
var createProcessLongFunctionSql = // function that takes @secondsNumber seconds
784+
@"CREATE OR ALTER FUNCTION dbo.[ProcessLong]
785+
(
786+
@secondsNumber int
787+
)
788+
RETURNS int
789+
AS
790+
BEGIN
791+
declare @startTime datetime = getutcdate()
792+
while datediff(second, @startTime, getutcdate()) < @secondsNumber
793+
begin
794+
set @startTime = @startTime
795+
end
796+
return 1
797+
END";
798+
var dropProcessLongFunctionSql = @"DROP FUNCTION IF EXISTS [dbo].[ProcessLong]";
799+
800+
using (var ctx = CreateContext(false))
801+
{
802+
try
803+
{
804+
ctx.Database.ExecuteSqlRaw(createProcessLongFunctionSql);
805+
ctx.Database.SetCommandTimeout(commandTimeout);
806+
807+
var query = from p in ctx.Products
808+
select NorthwindContext.ProcessLong(commandExecutionTime);
809+
810+
var exception = Assert.Throws<Microsoft.Data.SqlClient.SqlException>(() =>
811+
{
812+
var result = query.ToLinqToDB().First();
813+
});
814+
Assert.AreEqual(exception.Number, timeoutErrorCode);
815+
}
816+
finally
817+
{
818+
ctx.Database.ExecuteSqlRaw(dropProcessLongFunctionSql);
819+
}
820+
}
821+
}
777822
}
778823
}

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
variables:
22
solution: 'linq2db.EFCore.sln'
33
build_configuration: 'Release'
4-
assemblyVersion: 5.1.0
5-
nugetVersion: 5.1.0
4+
assemblyVersion: 5.1.1
5+
nugetVersion: 5.1.1
66
artifact_nugets: 'nugets'
77

88
# build on commits to important branches (master + release branches):

0 commit comments

Comments
 (0)