Open PrachiKakaiya opened 4 months ago
Few comments.
ComplexType
mechanism as a means to force expansion is a hacky approach: it was never meant for that, so I think you were doing it poorly even before the upgrade[DataMember]
to achieve camelCasing in the results: just configure the json serializer to do that. This will save you a ton of error-prone hardcoding.Expand()
method in your EDM building logic with the SelectExpandType.Automatic
setting to always expand properties for a give type like this:builder.EntitySet<Customer>("Customers").EntityType.Expand(SelectExpandType.Automatic);
Thank you for the help. It's working now.
Kindly assist us with another issue here.
Subject: Issue with Filtering in AspNetCoreOData After Expanding the Object
Problem Description:
We are currently using AspNetCoreOData version 7.20.0 and have encountered an issue with filtering after expanding objects. The problem manifests as a discrepancy in the data returned for specific OData queries, leading to incorrect results.
OData Query 1:
{{Base_URL}}/finance/odata/v2/payments/PaymentOperation.v2.GetByVendorType?vendor_type='publisher'&$filter=id eq 28965 and vendor/id eq 128493&$count=true&orderby=paid_at desc&$expand=bills($expand=offer;$count=true)
Response :
{
"@odata.count": 1,
"value": [
{
"id": 28965,
"paid_at": "2023-10-10T00:11:05.113Z",
"amount": 700.0000,
"vendor": {
"id": 128493
},
"bills@odata.count": 4,
"bills": [
{
"paid_amount": 300.0000,
"offer": null
},
{
"paid_amount": 100.0000,
"offer": null
},
{
"paid_amount": 200.0000,
"offer": {
"campaign_name": "Default",
"completed_at": null,
"finance_settled_at": null
}
},
{
"paid_amount": 100.0000,
"offer": {
"campaign_name": "Default",
"completed_at": "2023-10-09T03:09:33Z",
"finance_settled_at": "2023-10-09T03:09:33Z"
}
}
]
}
]
}
OData Query 2:
{{Base_URL}}/finance/odata/v2/payments/PaymentOperation.v2.GetByVendorType?vendor_type='publisher'&$filter=id eq 28965 and vendor/id eq 128493&$count=true&orderby=paid_at desc&$expand=bills($expand=offer;$count=true;$filter=offer/campaign_name eq 'Default')
Response :
{
"@odata.count": 1,
"value": [
{
"id": 28965,
"paid_at": "2023-10-10T00:11:05.113Z",
"amount": 700.0000,
"vendor": {
"id": 128493
},
"bills@odata.count": 2,
"bills": [
{
"paid_amount": 200.0000,
"offer": {
"campaign_name": "Default",
"completed_at": null,
"finance_settled_at": null
}
},
{
"paid_amount": 100.0000,
"offer": {
"campaign_name": "Default",
"completed_at": "2023-10-09T03:09:33Z",
"finance_settled_at": "2023-10-09T03:09:33Z"
}
}
]
}
]
}
Issue:
In the first query, we apply the filter id eq 28965 and vendor/id eq 128493
, which correctly returns four records in the bills
object with a total sum of 700 of paid_amount in amount field.
However, in the second query, when we add a filter to the expanded offer
object ($expand=bills($expand=offer;$count=true;$filter=offer/campaign_name eq 'Default')
), it returns only two records in the bills
object. Despite this, the amount
field at the root level incorrectly remains 700 instead of 300, reflecting the sum of the filtered records.
Request for Assistance:
We seek guidance on how to correctly calculate and display the amount
field in the API response when using AspNetCoreOData v7.20.0, given the current constraints. Specifically, we need:
We appreciate any insights or solutions that can help resolve this issue efficiently.
@PrachiKakaiya please avoid reopening an existing issue to ask a different question, even if it is a followup. Instead, move the new question to a new issue and just add a mention of your previous one if you want to relate them.
Also, it seems to me like your second question is a better fit for the Discussions
area as it doesn't appear to be a bug: you are just looking for guidance on how to create the desired query.
Issue with Object Expansion After Upgrading AspNetCoreOData
Background We were previously using AspNetCoreOData v7.14.0 for our API services. In this version, objects within the API response were expanding by default, facilitated by the use of the ComplexType attribute.
Problem After upgrading our services to .Net8, we updgraded the AspNetCoreOData library to v7.20.0, we encountered an issue where objects were no longer expanding automatically in the API responses. The key points of this problem are:
Attempted Solution To address this issue, we attempted the following:
Current Situation While the removal of the ComplexType attribute resolved the immediate issue of assembly bindings, it introduced a new problem: the default expansion of objects in the API response is no longer working.
Request for Assistance We are seeking guidance on how to achieve the default expansion of objects in the API response with AspNetCoreOData v7.20.0, given the current constraints. Specifically, we need:
We appreciate any insights or solutions that can help resolve this issue efficiently.
Please refer to this: