tags:

views:

192

answers:

1

Consider the following code block:

using (PlayersDataContext context = new PlayersDataContext())
{
    Console.WriteLine(context.Players.Count()); // will output 'x'
    context.Players.InsertOnSubmit(new Player {FirstName = "Vince", LastName = "Young"});
    Console.WriteLine(context.Players.Count()); // will also output 'x'; but I'd like to output 'x' + 1
}

Given that I haven't called

context.SubmitChanges();

the application will output the same player count both before and after the InsertOnSubmit statement.

My two questions:

Can the DataContext instance return collections that include pending changes?

Or must I reconcile the DataContext instance with context.GetChangeSet()?

+1  A: 

Sure, use:

context.GetChangeSet()

and for more granularity, there are members for Inserts, Updates, and Deletes.

EDIT: I understand your new question now. Yes, if you wanted to include changes in the collection, you would have to somehow combine the collections returned by GetChangeSet() and your existing collections.

JoshJordan
OK. Actually, my question pertains to more than just simple counts.For example, if I was interested in modified data, and I used context.GetChangeSet(), then I would need to fully reconcile the DataContext instance and context.GetChangeSet().Thanks for you answer, though. I reworded my question for clarity.
Jim G.
Gotcha. Yes, I see what you mean. I believe that doing to manual combination is the only way to go here.
JoshJordan
Thanks, Josh. I'll leave this question open for a bit; but otherwise, I think you're right.
Jim G.
Good luck. Do post if you find some alternative, this is a very interesting question.
JoshJordan