AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
141 stars 39 forks source link

$select query doesn't work #10

Closed iroman91 closed 4 years ago

iroman91 commented 4 years ago

Instead of returning the specified properties from a $select query, GetAsync or GetQueryAsync will return all (selected + unselected) properties.

Model/Dto:

public class User {

 public int Id { get; set; }
 public string Name { get; set; }
}

OData select query: $select: id

GetAsync method:

ICollection<User> result = await sourceQueryable.GetAsync(mapper, odataOptions);

Output:

{
 Id: 1
 Name: "TestUser"
}
xaviervv commented 4 years ago

Is a known issue. Reported it as well with the previous issues. Author of package is aware. All dto properties are returned. Look at the issue regarding orderby

Get Outlook for Androidhttps://aka.ms/ghei36


From: Roman Ivakin notifications@github.com Sent: Thursday, February 6, 2020 10:29:51 AM To: AutoMapper/AutoMapper.Extensions.OData AutoMapper.Extensions.OData@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [AutoMapper/AutoMapper.Extensions.OData] $select query doesn't work (#10)

Instead of returning the specified properties from a $ select query, GetAsync or GetQueryAsync will return all (selected + unselected) properties.

Model/Dto:

public class User {

public int Id { get; set; } public string Name { get; set; } }

OData select query: $select: id

GetAsync method:

ICollection result = await sourceQueryable.GetAsync(mapper, odataOptions);

Output:

{ Id: 1 Name: "TestUser" }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/AutoMapper/AutoMapper.Extensions.OData/issues/10?email_source=notifications&email_token=AIMW3QURCYYPNP4IKPMGKZTRBPKA7A5CNFSM4KQZM4K2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ILONDKA, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIMW3QT33HSYEGAP3VGYQWLRBPKA7ANCNFSM4KQZM4KQ.

iroman91 commented 4 years ago

Thanks for your reply. Hopefully, the author will be able to fix this soon.

xaviervv commented 4 years ago

I was too quick to reply, my bad.

If you are talking about the json returned by the odata call, then the select should be applied correctly.

However, the generated SQL from EF Core includes all of the DTO properties instead of only the ones in the $select clause.

BlaiseD commented 4 years ago

No we need an implementation for $select to return an anonymous type. I'll leave this open until it's ready.

BlaiseD commented 4 years ago

Should be working using QueryableExtensions.GetQueryAsync in version 1.0.2-preview04. See the unit tests.

RobTF commented 4 years ago

Hi,

This doesn't appear to work in the latest version (1.0.5) when the DTO has non-nullable value typed properties on it. These still come through (albeit as their natural "default" value).

BlaiseD commented 4 years ago

@RobTF - what you've described should work - see the tests.

If not - maybe open an issue with code for the failing scenario.