Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RIA服务不更新空外键_C#_Entity Framework_Silverlight_Code First_Ria - Fatal编程技术网

C# RIA服务不更新空外键

C# RIA服务不更新空外键,c#,entity-framework,silverlight,code-first,ria,C#,Entity Framework,Silverlight,Code First,Ria,我对RIA服务有一个奇怪的问题。我在EF CodeFirst(v4.1)上下文中有两个实体,客户和地址,它们之间的关系为1:1 public class Customer { [Key] public int Id { get; set; } // [...] [Include, Association("Customer_BillingAddress", "BillingAddressId", "Id")] public virtual Addres

我对RIA服务有一个奇怪的问题。我在EF CodeFirst(v4.1)上下文中有两个实体,
客户
地址
,它们之间的关系为1:1

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);
RIA服务不会更新ID,导致服务器上出现外键约束错误。我检查了导航属性,保存时外键设置为
null
。因此,当我将属性设置为
null
时,RIA服务似乎没有跟踪该属性。我怎样才能解决这个问题

编辑:我完全忘记了:它可以在我的开发机器上工作,但不能在部署上工作。

Ghch。。。找到了答案。底线:将
[RoundtripOriginal]
属性应用于
客户

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