0

We're using WCF Data Services (.NET 4 currently - planning to upgrade to WCF Data Services 5 at some point) to expose some data from a SQL DB. We're projecting that data, server-side, into a public domain model and then exposing the data via the Reflection provider.

This all works fine, except I recently added some syndication details to the domain model so that it looks a bit nicer in feed views in e.g. IE. Here's the sort of thing I've done: -

[DataServiceKey("ID")]
[EntityPropertyMapping("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, false)]
public class Customer
{
    public String Name { get; set; }
    public String ID { get; set; }
    public Boolean IsActive { get; set; }
}

And this correctly works insofar as the feed correctly has the syndicate field set and it shows up in IE nicely. In addition, the Name field no longer appears directly in the XML of the data. Instead, when I get a client-side reference in a Console or Silverlight application, the proxy class has attributes on it like so (I've elided the other attributes) :-

[global::System.Data.Services.Common.EntityPropertyMappingAttribute("Name", System.Data.Services.Common.SyndicationItemProperty.Title, System.Data.Services.Common.SyndicationTextContentKind.Plaintext, false)]
[global::System.Data.Services.Common.DataServiceKeyAttribute("ID")]
public partial class Customer : global::System.ComponentModel.INotifyPropertyChanged { // etc. }

Ignoring the INotifyPropertyChanged, the main thing is the SyndicationItemProperty which I assume allows the client-side proxy to correctly rehydrate the object correctly. However, on our ASP .NET application (WebForms or MVC), we get this sort of behaviour instead: -

[global::System.Data.Services.Common.DataServiceKeyAttribute("ID")]
public partial class LegalEntity { // etc. }

i.e. It correctly generates Key Attribute, but does not generate the Syndication Title attribute, so the client does not know how to hydrate the Name property; instead, it just comes back as null. If I turn off the syndication, it all works.

This seems to me to suggest that the template that generates code is different for different project types in VS and there's an issue with the MVC one that does not support syndication.

How can I get around this without having to resort to manually creating partial classes and decorating them with the extra attribute (or turning off the syndication)?

Added subsequently:

I've now discovered that the difference is that in the .datasvcmap file for ASP .NET projects, the following XML is absent: -

<Parameters>
   <Parameter Name="UseDataServiceCollection" Value="true" />
   <Parameter Name="Version" Value="2.0" />
</Parameters>

Adding that in seems to fix the problem. The question that remains is why doesn't it get added automatically?

Thanks

4

1 回答 1

1

如果使用命令行工具 DataSvcUtil 生成代码,则有 1.0 或 2.0 的版本切换:

http://msdn.microsoft.com/en-us/library/vstudio/ee383989(v=vs.100).aspx

似乎您获得了版本为 1.0 的 ASP/MVC 输出和版本为 2.0 的控制台/Silverlight - 可能只是巧合,但值得注意。

datasvcutil /out:c:\dnh.cs /uri:http://server/DataServices/Customers.svc/ /version:1.0
datasvcutil /out:c:\dnh.cs /uri:http://Server/DataServices/Customers.svc/ /version:2.0
于 2012-10-15T11:14:11.793 回答