0

I have an issue with poco classes in EF 4.

I have an Order entity wich contains a foreign key to a Customer entity.

So, the Order class has a navigation property of type Customer.

It's look like this :

public class Order
{
     public virtual int Id { get; set; }
     public virtual CustomerId  { get; set; }
     public virtual Customer customer { get; set;}
     …
}

When I load an order, the navigation property customer is correct, but if the CustomerId property changes, the navigation property is not refresh with the new customer.

If I call the DetectChanges() method on the EF context, the navigation property is then refreshed.

I've read that with all properties marked as virtual, the relationship synchronisation is automatic, but it's not the case here.

Where did I go wrong ?

Thanks for any help

  • I just tested this and for me it works as expected. Can you show more details, please? The query you are running and the subsequent code until you change the FK property, the exact EF version you are using and if ObjectContext or DbContext, etc. Also please check in the debugger if the loaded order and customer are dynamic proxies. – Slauma Nov 06 '12 at 22:02

1 Answers1

0

It means that for some reason proxy was not created for you entity. Take a look at this blog post - http://blogs.msdn.com/b/adonet/archive/2009/12/22/poco-proxies-part-1.aspx. Here are the requirements for creating proxies: http://msdn.microsoft.com/en-us/library/vstudio/dd468057(v=vs.100).aspx. Proxy creation must not be disabled.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • Thanks for these helpful links. It helps me to better understand the use of proxies, and check what could be wrong in my code. Finally, the problem came from another navigation property wich was not well implemented. – Morgann Moussier Nov 07 '12 at 13:06