2012-09-17 82 views
2

確定這是發生了什麼。我有兩個應用程序 - 一個WCF數據服務和一個MVC應用程序。Context.UpdateObject()不傳遞對象中的集合

我們正在審查一個有兩個集合的類型。的簡單類型

[DataServiceKey("Id")] 
    [ETag("ModifiedDate")] 
    public class AllocationRule 
    { 

     public AllocationRule() 
     { 
      Zones = new List<Zone>(); 
     } 

     public int Id { get; set; } 

     public string Name { get; set; } 

     public List<Zone> Zones { get; private set; } 
    } 

區域如下所示

[DataServiceKey("Code")] 
    [EntityPropertyMapping("Name", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true)] 
    [EntityPropertyMapping("ModifiedDate", SyndicationItemProperty.Updated, SyndicationTextContentKind.Plaintext, true)] 
    [ETag("ModifiedDate")] 
    public class Zone 
    { 
     public string Code { get; set; } 

     public string Name { get; set; } 

     public DateTime? ModifiedDate { get; set; } 
    } 

所以MVC網站試圖插入像這樣

var context = new ChannelData(new Uri(ConfigurationManager.AppSettings["DataServicesUri"])); 
        context.AddToAllocationRules(rule); 
        context.SaveChanges(); 

的對象,當我們這樣做,區域的集合在odata方面始終爲空,並且在MVC方面不爲空。

有什麼想法?我們不能使用提琴手等來嗅探請求,因爲我們仍處於本地開發階段。

更新

當我們使用一個WinForms應用此相同的數據類型回發到WCF數據服務,我們沒有看到這些藏品無論是。

看起來好像他們在帖子請求中迷路了。

我們可以從服務中檢索數據,$ expand()工作。

下面是來自Fiddler2

<?xml version="1.0" encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><category term=" Data.Services.Entities.AllocationRule" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
<id /><title type="text">dfsdsdf</title><published>0001-01-01T00:00:00-05:00</published> 
<updated>2012-09-18T15:44:36-04:00</updated><author><name /> 
</author><content type="application/xml"><m:properties><d:Amount m:type="Edm.Int32">50</d:Amount><d:CreatedBy m:null="true" /> 
<d:CreatedDate m:type="Edm.DateTime">0001-01-01T00:00:00</d:CreatedDate><d:EffectiveEndDate 
m:type="Edm.DateTime">2012-12-18T15:44:30.1686832-05:00</d:EffectiveEndDate><d:EffectiveStartDate 
m:type="Edm.DateTime">2012-09-19T15:44:30.1696833-04:00</d:EffectiveStartDate><d:Enabled 
m:type="Edm.Boolean">true</d:Enabled><d:Finalized m:type="Edm.Boolean">false</d:Finalized><d:Id 
m:type="Edm.Int32">0</d:Id><d:ModifiedBy m:null="true" /><d:ModifiedDate m:type="Edm.DateTime" 
m:null="true" /> 
<d:Name>dfsdsdf</d:Name><d:UnitOfMeasure>hours</d:UnitOfMeasure></m:properties></content></entry> 
+1

你甚至可以在本地使用fiddler,只要確保你使用的是http:// machinename而不是http:// localhost - 並且它應該可以工作。除此之外,你的意思是「收集在數據方面是無效的」?你是怎麼檢查的? –

+0

抱歉,標籤之前沒有ASP.NET MVC。更新問題以顯示結果與提琴手。 – PaulBinder

回答

1

我猜你加入了一個區的對象集合在其中添加合適的規則對象上的標題?如果這就是你所做的一切,那麼這就是預期的行爲。 WCF DS客戶端不處理導航屬性更改automagicaly。您需要:

在所有要添加的區域對象上調用context.AddObject,並調用context.SetLink來創建兩個對象之間的關係。

或者你可以使用context.AddRelatedObject添加Zone對象並一次性創建關係。