0
votes

I have a weird issue with RIA Services. I have two entities in my EF CodeFirst (v4.1) context, Customer and Address, that are in a 1:1 relation to each other.

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

    // [...]
}

I configured them with the model builder like so:

modelBuilder.Entity<Customer>()
    .HasOptional(p => p.BillingAddress)
    .WithMany()
    .HasForeignKey(x => x.BillingAddressId);

as described in this blog article. It all works like a charm, but when I want to do this on the client:

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

RIA Services won't update the ID, leading to a foreign key constraint error on the server. I checked, that the navigation propert yand the foreign key get set to null at the time of saving. So it seems like, RIA Services is not tracking the property when I set it to null. How can I fix that?

EDIT: I completely forgot: It works on my dev machine, but not on the deployment.

1

1 Answers

1
votes

Ghch... Found the answer here. Bottom-line: apply the [RoundtripOriginal] attribute to the Customer class.