Let's say I have a database that stores Fruit
and FruitBasket
s, and it's already populated with plenty of each. In my code I'm using Linq-to-Sql so that I can treat the rows of the database as instances of the OO classes Fruit
and FruitBasket
. Let's say that I want to create a temporary FruitBasket
in code, process with it, but I do not want the FruitBasket
to be persisted to the database. How do I achieve this using Linq-to-Sql?
The default I've found in Linq-to-Sql is that if I create a new, empty FruitBasket
and add a Fruit
to it that I had retrieved from the database, then the new FruitBasket
will be automatically inserted to the data base upon my call to dataContext.SubmitChanges()
(whether or not I have called insertUponSubmit()
). Usually this is the right thing , but sometimes I want to be able to create a new FruitBasket
without having it automatically inserted into the DB. Ideas? Best practices?