EF Core creates a proxy of value object and when comparing they won't be equal.
For eg:
Address shippingAddress = Address.From("City", "State");
//for instance it has same values in each properties
//NOTE: ShippingAddress is marked virtual and lazy loading has been enabled
Address orderShippingAddress = dbContext.Orders.GetById(123).ShippingAddress;
Assert.Equal(shippingAddress, orderShippingAddress) ;// this will fail as orderShippingAddress is a proxy of Address class
EF Core creates a proxy of value object and when comparing they won't be equal. For eg: Address shippingAddress = Address.From("City", "State");
//for instance it has same values in each properties //NOTE: ShippingAddress is marked virtual and lazy loading has been enabled Address orderShippingAddress = dbContext.Orders.GetById(123).ShippingAddress; Assert.Equal(shippingAddress, orderShippingAddress) ;// this will fail as orderShippingAddress is a proxy of Address class
Should we avoid marking it as virtual??