Trying to get a property via lazy loading of a just added entity fails.
The only solution I've found until now is to decomment the commented code ,in other words to create another Manager which in turn creates another Context since each Manager has an instance of the Context and then re-query the entity.
I also tried creating a shared Context instance between all Managers but same result. Any idea why recreating the Context solves it and how to fix this?
Here is the code I use to test:
IOrderManager ordManager = new OrderManager();
[TestMethod]
public void CategoryFromOrder()
{
Order order = new OrderBuilder()
.SetCategory(2)
.SetLegalForm(8)
.SetClientIdentifier(new Random().Next(11111111,99999999).ToString())
.SetLastName("Chaouachi")
.SetFirstName("Saif")
.SetQuantity(450)
.SetStatus(Order.StatusValues.New)
.SetAccountHolder("John")
.SetPrimaryKey(PrimaryKeyFactory.GetOrderPrimaryKey(null, 1, 2))
.Build();
int res = ordManager.AddOrder(order);
//ordManager = new OrderManager();
// order = ordManager.GetOrder(PrimaryKeyFactory.GetOrderPrimaryKey(res, 1, 2));
var categ = order.Category;
Assert.IsNotNull(categ);
}