I am using .Net Core 2.2 OData in our project. I want to use default select query for an entity because I have sentive data for users and users can decide to share or not.
public IQueryable<User> Get()
{
return db.Users.Where(x => x.ShowProfile).Select(x => new User
{
Id = x.Id,
Name = x.Name,
Surname = x.Surname,
Photo = x.ShowPhoto && !string.IsNullOrEmpty(x.Photo) ? x.Photo : null,
Bar = x.Bar,
RegistrationNumber = x.RegistrationNumber,
PhoneNumber = x.ShowPhoneNumber && x.PhoneNumber != "-" ? x.PhoneNumber : null,
WorkPhoneNumber = x.ShowWorkPhoneNumber && x.WorkPhoneNumber != "-" ? x.WorkPhoneNumber : null,
Email = x.ShowEmail && x.Email != "-" ? x.Email : null,
//Profiles = x.Profiles //Error When This Line Uncommented
}).AsQueryable();
}
This code works well but if I use $expand and $filter for expand then I can't get a result and I need it.
I have tried an DTO model as UserDto and this is work well but result is not odata format and I can't use $count etc.
What is the correct way to apply?