This is a migrated thread and some comments may be shown as answers.

When are the entities available in the context after add?

1 Answer 38 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 2
Alex asked on 10 Apr 2012, 08:12 AM
Basically, I'd like to understand why this scenario fails:

context.Add(cisPart);
List<AudioProductsBuzzers> list = context.AudioProductsBuzzers.ToList<AudioProductsBuzzers>();

Where cisPart is an AudioProductBuzzers entity. The newly added instance does not appear in the list.

Regards,

Alex

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivailo
Telerik team
answered on 12 Apr 2012, 04:37 PM
Hi Alexis,

The reason why the new object is not presented in the list is that it is not yet saved to the database. When you add an object to the context it is not automatically accessible through the collection, it is only marked for insertion in the database.

You have two options - either call SaveChanges() or FlushChanges() before the moment you need to access the new object through the context, so all the executed queries will consider it. Before that, you should just keep using the newly created object.

You can find some more details and examples in the Context API guide for handling transactions and performing CRUD operations.

I hope that clarifies the matter. Do not hesitate to get back to us if you have any questions.
 

Regards,
Ivailo
the Telerik team
Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Tags
Development (API, general questions)
Asked by
Alex
Top achievements
Rank 2
Answers by
Ivailo
Telerik team
Share this question
or