question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column Value Converters are not fired when using coalesce operator in a query

See original GitHub issue

Good day, Recently I noticed a bug in either this library or in the Linq2Db query engine itself - I am not sure where exactly. The issue is that when defining a custom value converter in EF Core db context (for nullable DateTime in my particular case) they are not being fired when a query is using coalesce operator. However in pure EF Core they work just fine.

Here is a sample query:

          using var context = container.GetService<SampleDataContext>();
          var query = from t2 in context.TableTwo
                      join t1 in context.TableOne on t2.TableOneId equals t1.Id into t1j
                      from t1 in t1j.DefaultIfEmpty()
                      select new
                      {
                          t2.Code,
                          NullableDateColumn = t2.NullableDateColumn, //here the converter is launched properly
                          FromDate = t1.FromDate ?? t2.FromDate, //here the converter is not launched
                          ToDate = t1.ToDate ?? t2.ToDate, //here the converter is not launched
                      };

          var results = query.ToLinqToDB().ToList();

I have also attached a full sample project with two Nunit tests where the issue can be easily reproduced and they use the above query: Linq2DbDateConvertersBug.zip The test named TestEFCore passes however the test named TestLinq2Db fails - they both use the same logic and query so they should both pass.

I use Linq2Db together with EF Core in many projects and for me this synergy is just awesome, however because of this bug I recently have quite a lot of headaches. I noticed this for datetimes with relation to coalesce operator, however I think this bug can be affecting also other types of converters and operators as well.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Jun 6, 2022

I have checked this particular case works.

0reactions
plukawskicommented, Jul 7, 2022

I have checked the newest release of Linq2Db 4.1.1 and I confirm all mentioned here issues are resolved. I am closing the issue as a result. Thanks for fixing this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the SQL Coalesce function in SQL Server
The SQL Coalesce function is used to select the columns homephone, workphone, and cellphone. In case of NULL values, the value 'NA' (not...
Read more >
How to Use SQL Server Coalesce to Work with NULL Values
It uses COALESCE to avoid concatenating the state to the @REGION_LIST variable when it is NULL which happens with the first row of...
Read more >
c# - null-coalescing operator ?? throws an error in LINQ
Following LINQ query throws error shown below when using null-coalescing operator ??. It works fine if I remove ?? 0 part. But I...
Read more >
Columns in COALESCE are not all the same data type
Message. Columns in COALESCE are not all the same data type · Description. The rule checks and warns if COALESCE function arguments do...
Read more >
Use of COALESCE() function in SQL Server
The SQL Server COALESCE() function is useful to handle NULL values. The NULL values are replaced with the user-given value during the expression ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found