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

Commit 8e886c1

Browse files
authored
Merge pull request #98 from linq2db/version3
Release 3.9.1
2 parents a43397c + 293a234 commit 8e886c1

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
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: 11 additions & 2 deletions
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());
@@ -68,7 +75,9 @@ private void ConfigureGlobalQueryFilters(ModelBuilder builder)
6875
public void ConfigureEntityFilter<TEntity>(ModelBuilder builder)
6976
where TEntity: class, ISoftDelete
7077
{
71-
builder.Entity<TEntity>().HasQueryFilter(e => !IsSoftDeleteFilterEnabled || !e.IsDeleted);
78+
NorthwindContext? obj = null;
79+
80+
builder.Entity<TEntity>().HasQueryFilter(e => !obj!.IsSoftDeleteFilterEnabled || !e.IsDeleted);
7281
}
7382

7483
public bool IsFilterProducts { get; set; }

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,5 +735,83 @@ from c2 in ctx.Categories.FromSqlInterpolated($"SELECT * FROM [dbo].[Categories]
735735
}
736736
}
737737

738+
[Test]
739+
public async Task TestDeleteFrom()
740+
{
741+
using (var ctx = CreateContext(false))
742+
{
743+
var query = ctx.Customers.Where(x => x.IsDeleted).Take(20);
744+
745+
var affected = await query
746+
.Where(x => query
747+
.Select(y => y.CustomerId)
748+
.Contains(x.CustomerId) && false
749+
)
750+
.ToLinqToDB()
751+
.DeleteAsync();
752+
}
753+
}
754+
755+
[Test]
756+
public void TestNullability([Values(true, false)] bool enableFilter)
757+
{
758+
using (var ctx = CreateContext(enableFilter))
759+
{
760+
int? test = 1;
761+
var query = ctx.Employees.Where(e => e.EmployeeId == test);
762+
763+
var expected = query.ToArray();
764+
var actual = query.ToLinqToDB().ToArray();
765+
766+
AreEqualWithComparer(expected, actual);
767+
}
768+
}
769+
770+
771+
[Test]
772+
public void TestCommandTimeout()
773+
{
774+
int timeoutErrorCode = -2; // Timeout Expired
775+
int commandTimeout = 1;
776+
int commandExecutionTime = 5;
777+
var createProcessLongFunctionSql = // function that takes @secondsNumber seconds
778+
@"CREATE OR ALTER FUNCTION dbo.[ProcessLong]
779+
(
780+
@secondsNumber int
781+
)
782+
RETURNS int
783+
AS
784+
BEGIN
785+
declare @startTime datetime = getutcdate()
786+
while datediff(second, @startTime, getutcdate()) < @secondsNumber
787+
begin
788+
set @startTime = @startTime
789+
end
790+
return 1
791+
END";
792+
var dropProcessLongFunctionSql = @"DROP FUNCTION IF EXISTS [dbo].[ProcessLong]";
793+
794+
using (var ctx = CreateContext(false))
795+
{
796+
try
797+
{
798+
ctx.Database.ExecuteSqlRaw(createProcessLongFunctionSql);
799+
ctx.Database.SetCommandTimeout(commandTimeout);
800+
801+
var query = from p in ctx.Products
802+
select NorthwindContext.ProcessLong(commandExecutionTime);
803+
804+
var exception = Assert.Throws<Microsoft.Data.SqlClient.SqlException>(() =>
805+
{
806+
var result = query.ToLinqToDB().First();
807+
});
808+
Assert.AreEqual(exception.Number, timeoutErrorCode);
809+
}
810+
finally
811+
{
812+
ctx.Database.ExecuteSqlRaw(dropProcessLongFunctionSql);
813+
}
814+
}
815+
}
738816
}
739817
}

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: 3.9.0
5-
nugetVersion: 3.9.0
4+
assemblyVersion: 3.9.1
5+
nugetVersion: 3.9.1
66
artifact_nugets: 'nugets'
77

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

0 commit comments

Comments
 (0)