Reputation: 2879
I'm developing .net core ODATA web api application. I have EF entity Operation with Json serialized property PaymentProfile. I have problem with getting Operation.PaymentProfile.PaymentMethods property via ODATA request
Configuration of Operation fluent API:
modelBuilder.Entity<Operation>().Property(e => e.PaymentProfile).HasConversion(
v => JsonConvert.SerializeObject(v, JsonSerializerSettings),
v => JsonConvert.DeserializeObject<PaymentProfile>(v, JsonSerializerSettings));
PaymentProfile is entity with other properties like:
public ICollection<PaymentMethod> PaymentMethods { get; set; } = new List<PaymentMethod>();
public CascadeStrategy CascadeStrategy { get; set; }
When i get request with expan of CascadeStrategy, it works fine:
odata/Operations?$expand=PaymentProfile($expand=CascadeStrategy)&$top=1&skip=0
Server return correct odata objects
But if i expand PaymentMethods property, it return corruped data with 200 http status. Request:
odata/Operations?$expand=PaymentProfile($expand=PaymentMethods)&$top=1&skip=0
Response:
{"@odata.context":"http://localhost:5020/odata/$metadata#Operations(PaymentProfile(PaymentMethods()))","value":[
If i request PaymentProfile with expand PaymentMethods, it works fine too:
odata/PaymentProfiles?$expand=PaymentMethods&$top=1&skip=0
Operation and PaymentProfile are from different EF context.
How can i fix it and get Operation.PaymentProfile.PaymentMethods property? Any ideas?
UPD: "currepted data" means response is not finished and is a not valid JSON. Lookse like its only first 112 symbols of true response
Upvotes: 1
Views: 273
Reputation: 5114
Did you set the Accept
header when requesting CascadeStrategy
while PaymentMethods
didn't?
Accept: application/json;odata.metadata=none
In general, the request results have @odata.context
, which is what you call corrupted data. You can check this document.
If you don't want it to appear, you can add Accept
header like above, you can also add $format=application/json;odata.metadata=none
to the query string, which will remove odata metadata from the results:
odata/Operations?$format=application/json;odata.metadata=none&$expand=PaymentProfile($expand=PaymentMethods)&$top=1&skip=0
Upvotes: 1