Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linq query selecting only Id requests all columns from CDS #69

Open
filcole opened this issue Nov 15, 2020 · 5 comments
Open

Linq query selecting only Id requests all columns from CDS #69

filcole opened this issue Nov 15, 2020 · 5 comments
Labels
enhancement New feature or request Server Platform API Fix\Change Cannot be fixed client side, requires server side fix

Comments

@filcole
Copy link
Contributor

filcole commented Nov 15, 2020

The following Linq query will return all columns from CDS, I'd only expect the Id column to be returned.

                Guid accountId = (from a in context.AccountSet
                                  where a.Name.Equals("Wonka Chocolate Factory")
                                  select a.Id).FirstOrDefault();

This occurs with latest versions of both clients:

  • Microsoft.PowerPlatform.Cds.Client, Version 0.2.31-Alpha
  • Microsoft.CrmSdk.XrmTooling.CoreAssembly, Version 9.1.0.51

Request:
image

Response:
image

The following query does not return all columns from CDS.

                Guid? accountId = (from a in context.AccountSet
                                   where a.Name.Equals("Wonka Chocolate Factory")
                                   select a.AccountId).FirstOrDefault();

Request:
image

Response:
image

To eliminate the cause being the Early Bound Generator in XrmToolbox I tested again with classes generated by CrmSvcUtil and received the same result.

Test code used for CrmServiceClient, CdsServiceClient and CdsServiceClientWithOOTBCrmSvcUtil are here: https://github.com/filcole/LinqDriverTest

@MattB-msft
Copy link
Member

Yes, this is long standing behavior of the Linq Client in our SDK. (since version 5 I believe )
the ID itself is always returned, thus if you ask for just the ID, the system translates that into the All. if you ask for ID and name, you will get only those 2 columns.

I will bring it up to the core team to see if they want to explore changing this behavior.

thanks
MattB

@jordimontana82
Copy link

Is this because the .Id property is not actually an attribute like .AccountId but a computed property?

(PS: I have always used the primary key attribute (.AccountId) for the very same reasons)

@filcole
Copy link
Contributor Author

filcole commented Nov 27, 2020

The reason I preferred using .Id instead of .AccountId is that .Id is a non-nullable Guid whereas .AccountId is generated as a nullable 'Guid?' by CrmSvcUtil (and Early Bound Generator).

This means we often have to introduce an unnecessary cast to 'Guid' which is ugly.

I expected the linq driver to only request the one field since that was all that's being requested. The results of the linq query just provide the one field, even though all fields are being transferred over the network.

With the current functionality I'd hope this code be reported by the solution checker, but it's not at the moment.

@filcole filcole changed the title Linq query selecting only Id requests AllColumns from CDS Linq query selecting only Id requests all columns from CDS Nov 27, 2020
@jordimontana82
Copy link

.AccountId.Value (which is what I do) is also an option there without casting, although if it's a primary key, then it should always have a value and so CrmSvcUtil could maybe generate it as just "Guid" ?

@MattB-msft MattB-msft added the enhancement New feature or request label Nov 30, 2020
@MattB-msft
Copy link
Member

Tagging this an "Enhancement request"... this seems like something the team can make better in the core and we will try to get this done in the future,

@MattB-msft MattB-msft added the Server Platform API Fix\Change Cannot be fixed client side, requires server side fix label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Server Platform API Fix\Change Cannot be fixed client side, requires server side fix
Projects
None yet
Development

No branches or pull requests

3 participants