Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Does Dapper support .NET 6?

Open JiProchazka opened this issue 4 years ago • 7 comments

I have read in some of the issues here that Dapper does not support .NET 6. Are there any known issues, or does it mean it just isn't tested with .NET 6? Dapper supports .NET 5 and it is a same .NET Standard as .NET 5, right? So it should be ok I guess... If there is really no support, will be? :) Thanks

JiProchazka avatar Nov 15 '21 14:11 JiProchazka

It has not support yet. For Example; linq ordefault enhancement released in .NET 6 which can return default value of T.

If you want to use this method in .net 6 project, you can add this method after using Query method. (Below code block)

Resource: https://dotnetcoretutorials.com/2021/09/02/linq-ordefault-enhancements-in-net-6/?series

    public static Product GetFirstOrDefaultProductByCriteria()
    {
        using (var connection = DbConnect.Connection)
        {
            var product = connection.Query<Product>("SELECT * FROM Products")
              .FirstOrDefault(x => x.UnitsInStock > 1000,
                              new Product { ProductId = 0, ProductName = "No Product" });

            return product;
        }
    }

mertmtn avatar Nov 16 '21 22:11 mertmtn

I'm not aware of any problems using Dapper with .NET 6, but we also haven't needed to make any specific changes for .NET 6 to date. On that subject, we may soon need to, depending on how ADO.NET providers add support for DateOnly/TimeOnly, but: nothing yet.

As for "It has not support yet." (@mertmtn) - sorry, I strongly disagree with that statement. We're not a LINQ provider - there's literally nothing for us to do for that.

mgravell avatar Nov 16 '21 22:11 mgravell

There's been a misunderstanding about my mention about "It has not support yet." I think, new changes with .NET 6 has not supported. Ex: Linq OrDefault enhancements released in .NET 6.

If we use QueryFirstOrDefault<T> method in .NET 6 project, we are not be able to pass default value of T object. It returns null below sample code.

Is possible to pass our default value of T type object?

Example usage resource: https://dotnetcoretutorials.com/2021/09/02/linq-ordefault-enhancements-in-net-6/?series

        public static Product GetProductById()
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                var id=50000;
                var query = "Select * From Products Where ProductId=@ProductId";

                return connection.QueryFirstOrDefault<Product>(query, new { ProductId = id });             
            }
        }

mertmtn avatar Nov 16 '21 22:11 mertmtn

@JiProchazka I migrated my project from .NET 5 to .NET 6, there was not encountered any problem for Dapper package. Repo Link: https://github.com/mertmtn/DapperCoreTutorial

mertmtn avatar Nov 16 '21 22:11 mertmtn

If you want to use LINQ, just use Query<T>(), then add any LINQ you want on the end - it should work absolutely fine. I don't think we'd add overloads for every possible LINQ usage - we also don't include a predicate form, and those have been in LINQ since LINQ was first introduced.

mgravell avatar Nov 16 '21 22:11 mgravell

I've been using Dapper with large .NET 6 projects for about 6 months in multiple projects with 0 issues so far.

gmalignon avatar Nov 18 '21 16:11 gmalignon

I've been using Dapper with large .NET 6 projects for about 6 months in multiple projects with 0 issues so far.

Same here.

SeppPenner avatar Jan 25 '22 10:01 SeppPenner