Posted on Nov 10, 2008

Linq To SQL Entity Data Context InsertOnSubmit vs Attach

After writing Unit tests lately I’ve been trying to test my business logic (which is all done in the Entity Manager) without actually submitting data to the database.  I’ll create my Items and Customers and do an InsertOnSubmit to get them into the Entity Manager context, but never call SubmitChanges().

This gets the data into the database, however, it does not get the objects into the EntityManager’s data context.  If I were to create a Customer Order and then create a Customer Order Item I can then Add the Customer Order Item to the Customer Order and the order item is then available within the Customer Order context, but the Customer Order is still not available within the Entity Manager context.  To do that, you need to Attach the Customer Order to the CustomerOrders table.

Comments are closed.

blog comments powered by Disqus