AspNetCoreOData
AspNetCoreOData copied to clipboard
DefaultSkipTokenHandler can't find a property in nested object when the same property name exists in the main object
Hi, I wasn't able to retrieve a nextlink with a $skiptoken value set to Category/Id, using below classes and configurations.
using nuget Odata/AspNetCoreOData 8.0.5
// odata query: /products?$orderby=Category/Id
public class Product {
public Guid Id { get; set; }
public Category Category { get; set; }
}
public class Category {
public Guid Id { get; set; }
public string Code { get; set; }
}
// startup.cs
builder.EntitySet<Product>("products");
Did I forgot something such as an attribute on the Category/Id field, or a configuration on the edm ? (I can't use the NotMapped attribute because I need to be able to order or filter on Product.Id)
If I didn't miss an attribute or a configuration, then here is what prevents me from getting the right skiptoken:
Category has a property 'Id' which share the same name as the property 'Id' from Product. In the DefaultSkipTokenHandler.GenerateSkipTokenValue() line 139 or 143, implementation get the property name from the model (Product) and doesn't take into account the edmProperty Type (in my case, Category), when it resolves its value.
I wasn't able to retrieve a nextlink
What exactly do you mean by that? Was the nextlink wrong? Was it missing? Do you have server-driven paging and expected a nextlink to appear? What query did you fire?
Query: http://127.0.0.1/odata/products?$count=true&$orderby=Category/Id In the response I should get:
"@odata.nextLink": "http://127.0.0.1/odata/products?$count=true&$orderby=Category/Id&$skiptoken=category/id-9c443839-fae9-4a7a-83a8-7f7d9db0c280,id-6ddd9649-4bf4-47c9-b2ff-51a1dbb71e6e"
but I get this instead:
"@odata.nextLink": "http://127.0.0.1/odata/products?$count=true&$orderby=Category/Id&$skiptoken=id-6ddd9649-4bf4-47c9-b2ff-51a1dbb71e6e,id-6ddd9649-4bf4-47c9-b2ff-51a1dbb71e6e"
@shinsentoh-indep can you elaborate why you should get the other link? I was under the impression that the token would always refer to the main entity, in this case the Product.
Are you sure the link you are getting is really wrong?
Well, if you try above code but with an $orderBy=Category/Code, you'll get a $skipToken=Category/Code-xxxxx,id-xxxxxxx. If you try with $orderBy=Category/Id, you will get '$skiptoken=id-6ddd9649-4bf4-47c9-b2ff-51a1dbb71e6e,id-6ddd9649-4bf4-47c9-b2ff-51a1dbb71e6e' which is caused by https://github.com/OData/AspNetCoreOData/blob/69eec03c7003fe12d92cdc619efdc16781683694/src/Microsoft.AspNetCore.OData/Query/Query/DefaultSkipTokenHandler.cs#L143 implementation which gets the value on the parent object instead of the child one. this is why you have the 'id-6ddd9649-4bf4-47c9-b2ff-51a1dbb71e6e' twice in the previous $skipToken.