Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithOptions<T> looses CommandTimeout property #4476

Open
Usaga opened this issue Apr 12, 2024 · 0 comments · May be fixed by #4477
Open

WithOptions<T> looses CommandTimeout property #4476

Usaga opened this issue Apr 12, 2024 · 0 comments · May be fixed by #4477
Assignees
Labels
Milestone

Comments

@Usaga
Copy link
Contributor

Usaga commented Apr 12, 2024

Describe your issue

Seems that configuring context with AddLinqToDBContext has two ways to set DataContextOptions. One of which looses parameters.

using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using LinqToDB;
using LinqToDB.Data;
using LinqToDB.AspNet;
using LinqToDB.DataProvider.SqlServer;

namespace ConsoleApp1;

internal sealed class DbContext : DataConnection
{
    public DbContext(DataOptions options) : base(options)
    {
        Debug.Assert(options.DataContextOptions.CommandTimeout == 91); // always ok
        Debug.Assert(CommandTimeout == 91); // failing
    }
}

static class Program
{
    static void Main()
    {
        var services = new ServiceCollection();

        services.AddLinqToDBContext<DbContext>((provider, options) =>
        {
            return options
                .UseSqlServer("some conn string", SqlServerVersion.v2019, SqlServerProvider.MicrosoftDataSqlClient)
                .WithOptions<DataContextOptions>(o => o with { CommandTimeout = 91 }) // this failing
                // .WithOptions(options.DataContextOptions with { CommandTimeout = 91 }) // this works
                ;
        });

        var container = services.BuildServiceProvider();

        container.GetService<DbContext>();

        System.Console.WriteLine("Ok");
    }
}

Environment details

Linq To DB version: 5.4.1

Database (with version): SQL Server 2019

ADO.NET Provider (with version): Microsoft.Data.SqlClient 5.20

Operating system: Windows 10

.NET Version: .NET Core 6

igor-tkachev added a commit that referenced this issue Apr 14, 2024
@igor-tkachev igor-tkachev linked a pull request Apr 14, 2024 that will close this issue
@igor-tkachev igor-tkachev linked a pull request Apr 14, 2024 that will close this issue
@MaceWindu MaceWindu added this to the 5.v.Next milestone Apr 15, 2024
igor-tkachev added a commit that referenced this issue Apr 16, 2024
@igor-tkachev igor-tkachev self-assigned this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants