• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Query ObjectContext

Is there a method to query an entity in ObjectContext before save changes?
I'm thinking look like a dataset where datable are local resources accessible locally before saving changes in the original database. Is the same with entity framework?
In my project I've added some records to an entity and I wont to know if a particular record is present before using SaveChanges method. Is possible?
0
fantamen
Asked:
fantamen
  • 4
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
If you are talking about the change set for the ObjectContext, that would be something like this:

ObjectContext.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added)

Open in new window

0
 
fantamenAuthor Commented:
Savant what I have to do is a selection in one table of the data model where i have added some records but I don't call SaveChanges. Is possible?
0
 
Bob LearnedCommented:
That would be "idiot savant" today...I don't understand that scenario.  What do you mean by "added some records"?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fantamenAuthor Commented:
I'm an idiot, not you!
To add I've used the method: objectcontext.AddTo<entity name>(name of the entity object)
What I don't understand is if I don't call objectcontext.SaveChanges is there a way to made a selection query in the entity object modified?

Thank you
0
 
Bob LearnedCommented:
Can you explain the "bigger picture" here?  Are you saying that you want to add an entity to the ObjectContext, and then change the state of the entity?
0
 
fantamenAuthor Commented:
Probably I'm not able to explain... I'm thinking look like a dataset. In a dataset i can add rows to a datatable and then obtain each one quering the dataset. So I work disconnected. Is there the possibility to do something like this in the Entity Framework?
0
 
CodeCruiserCommented:
So you want to query the objectcontext and want it to include the entities in the resultset which have not been saved to db by using savechanges?
0
 
fantamenAuthor Commented:
Yes... if is possible. In some occasions can be useful to don't open connection to the database and work locally.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now