tags:

views:

20

answers:

1

Giving the following code:

Animal a = new Animal { Name = "Rover", Type = "Dog" };
ctx.Animal.InsertOnSubmit(a);

Lets say the preceding code is in a method that gets called multiple times. I do not want to submit the same object twice. Would it be possible to query the DataContext using GetChangeSet() to see if this object already exists in the ChangeSet?

GetChangeSet().Insert returns an IList<object> I am drawing a blank as to how to find it.

+1  A: 

Figured it out... Using the question's code

ctx.GetChangeSet().Inserts.Any(ani => ani as Animal != null 
                                   && ((Animal) ani).Name == a.Name); 
Mike Fielden