Question

We are using the OData Provider Toolkit to expose custom data as an OData feed. We have noticed that the author field is always unset:

<entry>
  <id>http://localhost/sample.svc/Entity</id>
  <title type="text"/>
  <updated>2013-01-30T01:02:28Z</updated>
  <author>
    <name/>
  </author>

Is there a way to set the author programmatically using this toolkit? We haven't been able to find a way to access the SyndicationItems of the associated Atom feed that generates the result.

Was it helpful?

Solution

Depending on which version of WCF Data Services (ie System.Data.Services.DataService) you are using with that toolkit, you have two options here:

1) Use so-called 'Entity Property Mapping' to tell the system to put a specific property's value into the Author field. This functionality has been present since .NET 4.0 (and available through an update to 3.5SP1 as well). To turn this on, look into the ResourceType.AddEntityPropertyMappingAttribute API (http://msdn.microsoft.com/en-us/library/system.data.services.providers.resourcetype.addentitypropertymappingattribute.aspx).

2) Customize the instances of ODataEntry being written out using the recently added support for wrapping the ODataWriter being used by the data service. This is only available in versions 5.1 and later, which can be found at NuGet (http://nuget.org/packages/Microsoft.Data.Services/). To wrap the writer, you will need to hook up to the DataService.CreateODataWriter delegate property. You can see an example of how to use this here: http://odatasamples.codeplex.com/SourceControl/changeset/view/be77d3cacb2c#WcfDataServices101/WcfDataServices101.CustomizedEntityLinks/CustomizedEntityLinksService.svc.cs. Once you are in the WriteStart method, you can use the ODataEntry.Atom() extension method to get access to the atom-specific metadata like authors, contributors, etc.

Hope that helps, I can provide more exact code examples as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top