I have web app which invokes OData Webservice (DataServiceContext
) via a proxy. The issue is the code even though makes a call to OData webservice every time, it always returns old data after changing content in the Content Management system (SDL Tridion).
string getPageContentForUrl(string url)
{
var page = cdService
.Pages
.Expand("PageContent")
.Where(x => x.Url == url)
.FirstOrDefault();
if (page == null || page.PageContent == null)
{
return string.Empty;
}
else
{
return page.PageContent.Content;
}
}
We had to an reset the apppool to see the latest data changes.
So while debugging more, I noticed that
var context = (System.Data.Services.Client.DataServiceContext)cdService;
context.Entities[0].State = Unchanged
so I tried fixing it by calling .Detach()
explicitly before returning the value from getPageContentForUrl
, so something like,
cdService.Detach(page);
cdService.Detach(page.PageContent);
My question is, can I do the above at more "global" level, maybe have webservice always assume the State as "Changed", since I don't want to manually write code to Detach()
?