For example, say I am either creating or fetching some entities that I later plan to insert, update, or discard:
foreach (var foo in foos) {
if (foo.condition)
_myEntityCollection.Add(new Some_Entity_Type());
else
_myEntityCollection.Add(dc.Some_Entity_Types
.Where(t => t.ID == someID).FirstOrDefault());
}
When it comes time to, say, revert, I may do this:
// Exception gets thrown here if entity didn't exist in data context
_myEntityCollection.ForEach(t => dc.Refresh(RefreshMode.OverwriteCurrentValues, t));
I want to be able to iterate through _myEntityCollection and determine if the entity was one I fetched, or if it was a new one.
You could use the object state manager to test if the object context is aware of a specific entity.
UPDATE
The code from above works for the Entity Framework but the question concerns LINQ to SQL. You could try to inspect the
ChangeSetreturned byDataContext.GetChangeSet(). It contains three lists for added, deleted and updated entities.