2012-10-15 13 views
0

我們正在使用WCF數據服務(當前計劃升級到WCF數據服務5)以公開SQL數據庫中的某些數據。我們將這些數據(服務器端)投影到公共領域模型中,然後通過反射提供者公開數據。MVC項目中客戶端代理中缺少WCF數據服務聯合領域

這一切都工作正常,除了我最近添加了一些聯合的細節到領域模型,以便它看起來好一點在飼料視圖在例如。 IE瀏覽器。下面是諸如此類的事情,我做: -

[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; } 
} 

而這個正確的工作只要進了正確的銀團場集,它在IE中很好地顯示出來。另外,名稱字段不再直接出現在數據的XML中。取而代之的是,當我在一個控制檯或Silverlight應用程序客戶端參考,代理類都有像這樣於它的屬性(我省略掉其他屬性): -

[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. } 

忽略INotifyPropertyChanged的,主要事情是我假設的SyndicationItemProperty允許客戶端代理正確地重新水化對象正確。然而,在我們的ASP .NET應用程序(Web窗體或MVC),我們得到這樣的行爲,而不是: -

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

即它正確生成的關鍵屬性,但不會產生聚合Title屬性,因此客戶端不不知道如何保護Name屬性;相反,它只是返回爲空。如果我關閉聯合,它一切正常。

在我看來,這似乎表明生成代碼的模板對於VS中的不同項目類型是不同的,並且MVC不支持聯合發佈。

如何解決這個問題而不必訴諸手動創建部分類並使用額外屬性裝飾它們(或關閉聯合)?

隨後加入:

現在我已經發現,不同的是,在ASP .NET項目.datasvcmap文件,下面的XML不存在: -

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

並稱,在似乎解決問題。這個問題仍然存在,爲什麼它不會自動添加?

感謝

回答

1

如果您使用命令行工具DataSvcUtil生成的代碼中有1.0或2.0版本切換:

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

看來你的ASP/MVC輸出,版本:1.0和版本: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 
+0

有沒有辦法在Visual Studio中控制它?我們不希望每次都這樣做。 –

相關問題