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.

Query generation issues when using ODATA

See original GitHub issue

Worked through a few more of my ODATA examples, I’ve discovered a few further issues with query generation when using Microsoft ODATA WebApi (https://github.com/OData/WebApi) for .net core 3.1. I’m using a build from commit 8cd544b for linq2db in the master branch with the fix for #2070

Sample project here: https://github.com/djkunkel/linq2db-aggregate-odata-sample

The following requests fails to generate SQL:

Without orderby:

/odata/People?$apply=groupby((Title),aggregate(YearsExperience with countdistinct as Test))

With orderby:

/odata/People?$apply=groupby((Title),aggregate(YearsExperience with sum as TotalExperience))&$orderby=TotalExperience
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with min as Test))&$orderby=Test
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with max as Test))&$orderby=Test
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with average as Test))&$orderby=Test
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with countdistinct as Test))&$orderby=Test

The following cases do work for reference:

/odata/People?$apply=groupby((Title),aggregate(YearsExperience with sum as Test))
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with average as Test))
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with min as Test))
/odata/People?$apply=groupby((Title),aggregate(YearsExperience with max as Test))
/odata/People?$apply=groupby((Title),aggregate($count as NumPeople))&$orderby=NumPeople
/odata/People?$apply=groupby((Title),aggregate($count as NumPeople))&$count=true
/odata/People?$apply=filter(Title eq 'Engineer' or Title eq 'QA')/groupby((Title),aggregate($count as NumPeople))&$count=true
/odata/People?$apply=groupby((Office/Name),aggregate($count as NumPeople))&$count=true
/odata/People?$apply=filter(Title eq 'QA')/groupby((Office/Id,Office/Name),aggregate($count as NumPeople))&$count=true&$orderby=NumPeople desc
/odata/people?$expand=Office

Thank you for this project again!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sdanylivcommented, Mar 5, 2020

@djkunkel, version 2.9.7 will be released on Thursday. Dsitinct.Count queries will work but hey have non optimal SQL generation. If you expect COUNT (DISTICT x) - pity that it is not ready yet but i’m working on it.

2reactions
sdanylivcommented, Feb 13, 2020

I see, one team creates something not compatible with others. But I saw in OData code hacks for each EF version. Workarounds can not help if there are no test cases on EF side.

Anyway OData team are also clever guys, they have defined dynamic aggregation without generating run-time classes on the fly. I was surprised with the idea to just inject into JSON serialization with specially prepared classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ODATA Date Filter - Generating sql server query differently ...
ODATA Date Filter - Generating sql server query differently than expected - causing poor performance · There are three versions of EF Core....
Read more >
Get Items with ODATA Query Suddenly Failing
Solved: Hi all, I have a Flow that runs daily and uses several SharePoint Get Items actions, each with a different ODATA query....
Read more >
Issue while consuming BI query in OData service
While consuming BI query into OData service I am facing some issues. Details of the issues are as follows : Following this blog....
Read more >
Using OData.Feed and the Query option to avoid the dynamic ...
In my last post I showed how, in many cases, you can avoid the “dynamic data sources” error with OData data sources by...
Read more >
Why not OData?
There is virtually no contract. · The interface errs on the side of being too liberal in what it will accept. · The...
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