When creating an entity (with child entities) using POST with OData the response will only show the main Entity created. Child entities are ignored.
Use Expand on POST. What?! Seems a bit strange I’m sure but decorating your POST action with [EnableQuery] and wrapping the response in an OData SingleResult will adhear to the OData Expand on POST.
return Ok(SingleResult.Create(result));
The only issue with this is that you have to hit the DB with an Includes to get the fully formed newly created Entity plus child objects. So the result variable above will be assigned similar to below…..
var result = dbContext.ParentEntity.Include(“NameOfChildEntity”).Where(p => p.Id == myDbParentEntity.Id);
Carried out a discovery phase recently to look at Azure API Management and the key features gained by layering Azure’s API Manager (APIM) as a proxy/facade layer between your backend APIs. One of the elements of APIM that rather appealed to me was the “out of the box” caching.
Playing with an POC API and one Operation I was quickly up and running with caching by simply defining a Policy to my API operation.
The MSDN documentation here is easy to follow, along with the implementation. For an API operation that’s unlikely to change it’s just a case of adding an Inbound policy to carry out a cache lookup and a outbound query to store the backend API response.
The additional attributes basically form the cache key. So, if you want to cache based on the subscription key or the product for example that can be achieved by specifying true on the attributes you care about. Things get a little tricky when trying to invalidate the cache. In fact there doesn’t appear to be an easy way (or any way?!) to invalidate the cache. This doesn’t really give me the flexibility I need. So onto…….
Well it’s not really that hard but there’s not much documentation currently available on this approach. Even searches on StackOverflow result in empty responses and/or people complaining that Microsoft haven’t really made things easy here.
After a bit of trial and error I managed to get something like what I’d need. Basically, I used an approach of capturing the backend APIs response to a variable, storing this in the cache by a deterministic key and checking for this on Inbound requests then finally using some of the XSLT logic to either use the cached response in body of the response or call out to backend API for a fresh response.
Finally, I could then remove the cache key (and invalidate the cache) on POST, PATCH etc….
<cache-remove-value key=”getAllWidgets” />
Was playing with a POC app recently. I pushed out a web deploy to an Azure App Service. Everything built and deployed without issue. The app fired up and nothing just the vanilla error message returned. I checked the site logs via Kudu and nothing jumped out. Tried another deploy and no dice. So where do we go from here?
As I was in Kudu I navigated to the apps web.config and edited it to enable stdoutlogs.
I refreshed the site a couple of times to generate some log activity then opened the log file and realised that the SQL DB the app was talking to wasn’t enabled for Azure services. A quick SQL config and all was good.
Other causes of this error:
Spent a week at the Royal Mere hotel near Hersonosis in Crete with my mother. This was my 3rd time in Crete having being previously there to different parts of the island on a family holiday in the 80s and with my wife in 2011.
I’d visited a TUI 5 star resort before being at 1 in Croatia last year and was impressed with the food (good veggie options) and accommodation. The Royal Mere was a similar deal, no complaints really.
Spent a relaxing 7 days apart from the journey home. A 12 hour delay (which eventually turned into 13+ hours) welcomed us as we arrived at the airport. The TUI rep informed us that they’d take us to an all inclusive hotel for the evening. I remember thinking “we’re at their mercy now” and we were. The hotel was shocking. The rooms looked like a youth hostel. So glad we only stayed 12 hours in them. Needless to say I didn’t bother with the all inclusive or the room. Thankfully, I wasn’t here for the bulk of my stay and I’ve managed to block this from my memory (especially when the compo turns up)
Spent a day tidying up my old hallway. After toying with light grey then dark grey I decided that some colour was needed. A cheap pot of paint from B&Q, a free day and all was set……