I debugged this program without any results, and, unfortunately, I do not see the root of the problem. I get this exception: the ObjectContext instance has been deleted and can no longer be used for operations that require a connection.
There are 2 tables: - CustomerSet - OrderSet
The Customer_id field in the Orders table provides the relationship between the tables, as well as a virtual navigation property called Customer in the Orders table.
The scenario is as follows: I insert an item into the Orders table:
Order order = new Order();
Order.order_id = GenerateId(IdType.Order);
Order.date = DateTime.Now;
Order.Customer_id = GetCustomerId(tbCustomerName.Text);
Insert(order);
The Insert method has a DBContext method in the using statement, so it is automatically disposed of when necessary. I work inside of this.
After that I need data from a previously inserted element (for example, I need some property of the Customer field). And now I hope that the Customer field gets the value:
Order o = GetOrder(order.order_id);
And I got this o with an exception in the Customer field: o.Customer threw an exception like "System.ObjectDisposedException"
I played with lazy loading, turned on or off, but I did not work. The situation is the same ...
What am I facing?
What is really nice about this is that if I go in stages with the F11, it often works correctly!
Please, help! Thank you in advance.