OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
458 stars 158 forks source link

OData response gets truncated when using query features #403

Open stefan1st opened 2 years ago

stefan1st commented 2 years ago

OData response gets truncated when using query features.

Microsoft.AspNetCore.OData version 8.0.4

Without query parameters: image

With select query parameter: image

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddControllers(options =>
        {
            var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
            options.Filters.Add(new AuthorizeFilter(policy));
        }).AddNewtonsoftJson()
        .AddOData(opt => opt.EnableQueryFeatures().AddRouteComponents("odata", GetEdmModel()));

    ...
}

 private static IEdmModel GetEdmModel()
    {
        var builder = new ODataConventionModelBuilder();

        var entitySetConfiguration = builder.EntitySet<GenericDocument>("Documents");
        entitySetConfiguration.EntityType.HasKey(entity => entity.IdStr);

        return builder.GetEdmModel();
    }

DocumentsController

[HttpGet]
[EnableQuery]
public IActionResult Get()
{
    return Ok(_service.GetAll());
}

Model

[BsonCollection("my_documents")]
public class GenericDocument : Document
{
    public DateTime Date { get; set; }
    public string SupplierName { get; set; }
    public string SupplierAddress { get; set; }
    public string SupplierIban { get; set; }
    public string BuyerName { get; set; }
    public string BuyerAddress { get; set; }
    public string BuyerIban { get; set; }
    public string ProductCode { get; set; }
    public string ProductDescription { get; set; }
    public float Quantity { get; set; }
    public float Price { get; set; }
    public string Value { get; set; }
    public float TotalValueWithoutVat { get; set; }
    public float Vat { get; set; }
    public float Total { get; set; }
}

public abstract class Document : IDocument
{
    public string IdStr => Id.ToString();
    public ObjectId Id { get; set; }

    public DateTime CreatedAt => Id.CreationTime;
}

What could be the problem?

Some of the links, that I've checked:

https://devblogs.microsoft.com/odata/routing-in-asp-net-core-8-0-preview/ https://jira.mongodb.org/browse/CSHARP-1771?focusedCommentId=4145551&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-4145551 https://www.learmoreseekmore.com/2021/07/intro-on-odata-v8-in-dotnet5-api.html

xuzhg commented 2 years ago

@stefan1st What's the 'ObjectId' definition? What's the "_service" used in the controller? Is it a mongoDB or any other database?

Can you share a repro for us to dig more?

stefan1st commented 2 years ago

@xuzhg

_service

  private readonly IMongoRepository<GenericDocument> _repository;
        public IQueryable<GenericDocument> GetAll()
        {
            return  _repository.AsQueryable();
        }

ObjectId is MongoDB.Bson.ObjectId https://docs.mongodb.com/manual/reference/method/ObjectId/

I will get back to you with a repro.

Thanks

SymbioticKilla commented 2 years ago

@stefan1st Is it similar to this one? https://jira.mongodb.org/browse/CSHARP-3989 Mongo DB has a new Linq Provider that should actually support $select etc. clientSettings.LinqProvider = LinqProvider.V3;

But in my case it does not work. If you have some Repro can you please also share it with Mongo?