You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nullable object must have a value thrown for a query with DefaultIfEmpty() #30915
Hi,
I am getting error "Nullable object must have a value" using the following scenario:
varcategories=fromcindbContext.Set<AMOS_ADDRESSCATEGORY>().AsNoTracking()selectnew{Id=c.ADDRESSCATEGORYID,Name=c.DESCRIPTION};varaddresses=(fromaddressindbContext.Set<AMOS_ADDRESS>().AsNoTracking()
join cincategories on address.ADDRESSCATEGORYID equals c.Id into aCfromcategoryinaC.DefaultIfEmpty()selectnew{Id=address.ADDRESSID,Category=category}).ToArray();
The above scenarion works pefectly using EF Standard and works in EF Core if I change to:
varaddresses=(fromaddressindbContext.Set<AMOS_ADDRESS>().AsNoTracking()**join c in dbContext.Set<AMOS_ADDRESSCATEGORY>().AsNoTracking()**onaddress.ADDRESSCATEGORYID equals c.ADDRESSCATEGORYID into aC
from category inaC.DefaultIfEmpty()
select new{Id=address.ADDRESSID,Category=category}).ToArray();
Can you help me please?
Thanks in advance
Luigi
EF Core version: 8.0.0-preview.4.23259.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 6.0
Operating system:
IDE: Visual Studio 2022 17.4
Reacted by UliPlabst, Adrian Gonzalez, Luigi, Juan Pablo Cicero, George Savva, emanuelcasanova1, diegoangerossa, Sami, tmtoll, Peter Parke and 15 more
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
Note for triage: we don't handle assigning null to the anonymous type after calling DefaultIfEmpty, but it seems like this should work, and it works in LINQ-to-Objects.
Hi @ajcvickers
I believe it has same issue with non anonymous type.
Example:
varcategories=fromcindbContext.Set<AMOS_ADDRESSCATEGORY>().AsNoTracking()selectnewCategory{Id=c.ADDRESSCATEGORYID,Name=c.DESCRIPTION};varaddresses=(fromaddressindbContext.Set<AMOS_ADDRESS>().AsNoTracking()
join cincategories
on address.ADDRESSCATEGORYID equals c.Id into aCfromcategoryinaC.DefaultIfEmpty()selectnew{Id=address.ADDRESSID,Category=category}).ToArray();
Reacted by Luigi, Adrian Gonzalez, Peter Parke, Geri Parra, martinfrankjr and Vladimir Rudt
This issue is in the Backlog milestone. This means that it is not fixed in EF Core 8.0. We will re-assess the backlog and consider this item in the upcoming planning. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.
Hi, thanks for prompt reply. I believe that this issue should be with high priority because fails on a simple left join operation.
Anyway thanks for suggestion
Activity
ajcvickers commentedon May 17, 2023
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
Luigi6821 commentedon May 17, 2023
Hi @ajcvickers
Please find attached a project for reproducing issue.
ReproducibleNullObject.zip
ajcvickers commentedon May 18, 2023
Note for triage: we don't handle assigning null to the anonymous type after calling
DefaultIfEmpty, but it seems like this should work, and it works in LINQ-to-Objects.Luigi6821 commentedon May 19, 2023
Hi @ajcvickers
I believe it has same issue with non anonymous type.
Example:
Luigi6821 commentedon Nov 15, 2023
Hi, Has been solved in version 8 ?
I tested and seems still present..
Thanks in advance
ajcvickers commentedon Nov 15, 2023
This issue is in the Backlog milestone. This means that it is not fixed in EF Core 8.0. We will re-assess the backlog and consider this item in the upcoming planning. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.
Luigi6821 commentedon Nov 15, 2023
Hi, thanks for prompt reply. I believe that this issue should be with high priority because fails on a simple left join operation.
Anyway thanks for suggestion
UliPlabst commentedon Dec 20, 2023
I have the same exception using a simple group by statement, I think the root cause might be the same. You can run this in roslyn pad to reproduce.
Luigi6821 commentedon Feb 14, 2024
roji commentedon Feb 14, 2024
Luigi6821 commentedon Feb 15, 2024
51 remaining items
Default a value-type non-entity left-join projection to default(T) on…
Address PR feedback: fix marker comments and add SqlServer SQL baselines
Flip ValueTuple whole-object test to assert results after value-type …
Make the nullability marker survive GroupBy-element to-one subquery l…
Address review: guard non-grouping subquery clone, encapsulate marker…
Implement Seed30915 required by EF Core preview 7 specification tests
Upgrade to EF Core 11 preview 7 and sync tests with upstream
Upgrade to .NET 11 and EF Core 11 (preview 7), and xunit v3 (#294)