microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
700 stars 248 forks source link

Support combining nested LINQ Expand and Select #2439

Open duckblaster opened 6 months ago

duckblaster commented 6 months ago

Is your feature request related to a problem? Please describe the problem.

I am trying to select only a couple of properties from an expanded collection using LINQ, but .Expand() doesn't allow using .Select() on sub properties.

Describe the solution you'd like.

graphServiceClient
  .Me
  .Request()
  .Select(x => new { x.Id, x.Mail, x.DisplayName, x.Department })
  .Expand(x => new { MemberOf = x.MemberOf.Select(x => new { x.Id, x.DisplayName }) })

Additional context?

The query that I an trying to generate, that I have verified works in graph explorer: https://graph.microsoft.com/v1.0/me?$select=id,mail,department,displayName&$expand=memberOf($select=id,displayName)

MartinM85 commented 6 months ago

You can use Select and Expand which accept string

graphServiceClient
  .Me
  .Request()
  .Select("id,mail,department,displayName")
  .Expand("memberOf($select=id,displayName)")
duckblaster commented 6 months ago

Yes, I used that as a workaround, I just thought it would be great to have the option