How do I get original values for a navigation collection property, in EF Core?

3k Views Asked by At

My EF Core entity:

public class Order {
    public string Code { get; set; }  
    public ICollection<LineItem> LineItems { get; set; }  
}

I can get the original value for the Code property using:

context.Entry(myOrder).OriginalValues["Code"]

But if I try that for the LineItems navigation collection property, then it throws with:

The property LineItems on entity type Order is being accessed using the 'Property' method, but is defined in the model as a navigation property. Use either the 'Reference' or 'Collection' method to access navigation properties.

That exception message doesn't refer to methods I can find.

So how do I get original values for a navigation collection property?

0

There are 0 best solutions below