Closed Schinwinkwinsky closed 2 years ago
There are tests here using $select
- maybe compare those with your configuration.
I could see some differences. I set up my project using OData documentation. And it's like that:
using MediatR;
using Microsoft.AspNetCore.OData;
using Microsoft.EntityFrameworkCore;
using School.Data;
using School.Domain;
using School.WebAPI.Other;
using System.Reflection;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers()
.AddOData()
.AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);
But on your tests, OData is added on an IMvcCoreBuilder.
private void Initialize()
{
IServiceCollection services = new ServiceCollection();
IMvcCoreBuilder builder = new TestMvcCoreBuilder
{
Services = services
};
builder.AddOData();
I noticed that in your tests, you use OData v8.0.6. So I reverted to that version in my project and the result was the same. If you could test on my project, it's available on https://github.com/Schinwinkwinsky/School. I'd really appreciate your help.
It's probably better if you reproduce your failing case using the tests from this library - there are web tests calling controllers as well as tests creating the EDM model without the controller.
You're probably just missing an explicit expansion in your configuration e.g. compare the profiles here to yours.
Ok, I think I got it. I set up profile as your tests:
Before:
After:
When we query with $select, the properties not selected come with null or default value.
I think that's the reason all tests are ok. I don't know if it's a normal behavior, but when I use $select without AutoMapper, the properties not selected just don't come. It was not the result I expected. I'm not sure, but I thought ExplicitExpansion is to use with $expand query. Sorry, I'm new with OData and AutoMapper. Thank you for your help.
Yep - not sure what the difference is with other libraries. We project to the TModel
and return it.
PRs are welcome for any improvement.
With regard to explicit expansion, literal types are expanded by default unless a $select is specified. All members are eligible for expansion - not just navigation properties.
Thank you very much! I'm gonna study more and try to submit a PR.
Hello, everybody
Working with this extension I have noticed that OData $select query is not working with it. I have tested with: $top, $skip, $select, $expand, $filter and $orderBy. All kind of queries are working great, but $select.