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
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.