2014-01-09 45 views
0

我有一個奇怪的問題與RIA服務。我的EF CodeFirst(v4.1)上下文中有兩個實體,分別爲CustomerAddress,彼此之間的關係爲1:1。RIA服務不更新空外鍵

public class Customer 
{ 
    [Key] 
    public int Id { get; set; } 

    // [...] 

    [Include, Association("Customer_BillingAddress", "BillingAddressId", "Id")] 
    public virtual Address BillingAddress { get; set; } 
    public int? BillingAddressId { get; set; } 
} 

public class Address 
{ 
    [Key] 
    public int Id { get; set; } 

    // [...] 
} 

我與模型構建器配置他們像這樣:

modelBuilder.Entity<Customer>() 
    .HasOptional(p => p.BillingAddress) 
    .WithMany() 
    .HasForeignKey(x => x.BillingAddressId); 
this blog article描述

。這一切就像一個魅力,但我想這樣做在客戶端上:

customer.BillingAddress = null; 
customer.BillingAddressId = null; 

RIA服務將不會更新ID,導致服務器上的外鍵約束的錯誤。我檢查了導航屬性和外鍵在保存時設置爲null。因此,看起來,RIA Services在設置爲null時沒有跟蹤該房產。我該如何解決這個問題?

編輯:我完全忘了:它在我的開發機器上工作,但不在部署。

回答

1

Ghch ...找到了答案here。底線:將[RoundtripOriginal]屬性應用於Customer類。