By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright Β© All Rights Reserved. World of Software.
Reading: EF 9 Has a Bug Related to GroupBy Usage: GroupBy Throwing an Exception | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright Β© All Rights Reserved. World of Software.
World of Software > Computing > EF 9 Has a Bug Related to GroupBy Usage: GroupBy Throwing an Exception | HackerNoon
Computing

EF 9 Has a Bug Related to GroupBy Usage: GroupBy Throwing an Exception | HackerNoon

News Room
Last updated: 2025/02/19 at 11:37 AM
News Room Published 19 February 2025
Share
SHARE

EF9 has a bug and gives an exception “The given key ‘EmptyProjectionMember’ was not present in the dictionary.”

Abstract: Regular usage of EF9 sometimes throws the Exception “The given key ‘EmptyProjectionMember’ was not present in the dictionary.” It seems that is related to the bug in EF9 related to the usage of GroupBy.

I am using Microsoft.EntityFrameworkCore (9.0.2). In my code, I am using GroupBy like this:

 var query2 = query
             .GroupBy(contract =>
                             new { contract.BC_NR, contract.VERTRAGS_NR, contract.VERTRAGS_TYP }
                           )
             .Where(group => group.Any())
             .Select(group =>
                     group.OrderByDescending(contract => contract.CHANGE).First()
                    );

That is working fine when I materialize the query. But, if after that, I do some sorting, it throws an Exception.


var thisWorksFine = iQueryableTBS_VERTRAG2.ToList();
iQueryableTBS_VERTRAG2=iQueryableTBS_VERTRAG2.OrderBy(p=>p.VERTRAGS_NR);
var thisThrowsException = iQueryableTBS_VERTRAG2.ToList();

//Exception: The given key 'EmptyProjectionMember' was not present in the dictionary.

It can be seen in [1] that other people report the same issues. Obviously, that looks like a serious limitation of EF9, or better to say “a bug.”

2. Some Workarounds That Were Tried

There was some unusual workaround suggested on the internet, so I wanted to try it.


var thisWorksFine = iQueryableTBS_VERTRAG2.ToList();
string text22 = iQueryableTBS_VERTRAG2.ToQueryString();
iQueryableTBS_VERTRAG2= ctx.TBS_VERTRAG.FromSqlRaw(text22).AsNoTracking();
var thisStillWorksFine = iQueryableTBS_VERTRAG2.ToList();

iQueryableTBS_VERTRAG2 =iQueryableTBS_VERTRAG2.OrderBy(p=>p.VERTRAGS_NR);

var thisThrowsAnotherException = iQueryableTBS_VERTRAG2.ToList();

//Exception: 'FromSql' or 'SqlQuery' was called with non-composable SQL 
//and with a query composing over it. Consider calling 'AsEnumerable' 
//after the method to perform the composition on the client side.

So, that workaround would not work in my case. The problem is that generated SQL, in my case, contains parameter definitions, and the resulting query is not composable. Semicolons are the problem. Here is what my generated SQL looks like; the content of variable text22:

DECLARE @__bankClearing_0 int = 1;
DECLARE @__bankClearing_1 int = 1;

-- Contracts_ContractsListDT

SELECT [t7].[BC_NR], [t7].[VERTRAGS_NR], [t7].[CHANGE], [t7].[VERTRAGS_TYP], [t7].[AENDERUNG], 
[t7].[ARCHIV_BEZ1], [t7].[ARCHIV_BEZ2], [t7].[ARCHIV_BEZ3], [t7].[AUSZUEGE_BIS_VORTAGE], 
[t7].[BERATER_NR], [t7].[CONTRACT_COLLECTION], [t7].[DOCUMENT_BOX], [t7].[ERFASST_DURCH], 
[t7].[ERFOLGLOS_Z], [t7].[ERSTELLT], [t7].[FREIGABE1], [t7].[FREIGABE2], [t7].[FREIGABE_DATUM_1], 
[t7].[FREIGABE_DATUM_2], [t7].[GESPERRT], [t7].[GESPERRT_BIS], [t7].[GESPERRT_VON], 
[t7].[GLAEUBIGER_ID], [t7].[GLAEUBIGER_ID_LONG], [t7].[KUNDEN_NR], [t7].[LASTMOD], [t7].[LAST_CALL], 

......

3. No Better Practical Known Workaround

Article [1] mentions some other workarounds, but they didn’t look practical to me. I simply coded again my EF query to avoid the usage of GroupBy; even that approach might result in an ugly and slower query.

4. Bug in EF 9 Expected to be Fixed in EF 10

In article [1], a person called Shay Rojansky, a member of the Entity Framework team at Microsoft, promises that the bug will be fixed in EF 10. According to [2], the next planned stable release is EF Core 10.0, or just EF10, scheduled for November 2025.

So, until then, we are forced to do workarounds.

References

[1] https://github.com/dotnet/efcore/issues/31209

[2] https://learn.microsoft.com/en-us/ef/core/what-is-new/

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Confidence in air safety slips after DC crash: Survey
Next Article Apple’s first in-house iPhone modem is the C1
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

The OnePlus 13 is a great camera phone, and the OnePlus 15 could continue this trend
News
Review: Sonnet MacCuff mini – a well-designed M4 Mac mini mount [Video] – 9to5Mac
News
πŸ‘¨πŸΏβ€πŸš€ Daily – Airtel bets on itself |
Computing
Donald Trump hails former terrorist warlord as ‘a young, attractive guy’
News

You Might also Like

Computing

πŸ‘¨πŸΏβ€πŸš€ Daily – Airtel bets on itself |

3 Min Read
Computing

Top 10 AI Voice Recorders for Transcription and Content Creation

25 Min Read
Computing

Vulkan 1.4.315 With VK_EXT_zero_initialize_device_memory For VKD3D-Proton & More

2 Min Read
Computing

The HackerNoon Newsletter: The Startup Playbook Is a Lie. Ask Better Questions. (5/14/2025) | HackerNoon

2 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright Β© All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?