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

Query context with added but not saved entities

1 Answer 46 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David Ribb
Top achievements
Rank 1
David Ribb asked on 09 Jul 2011, 06:26 PM
When entities are created and added to the context (but NOT saved to the DB) they do not appear in the query context.Orders.All().ToList().  Is there a way to return them in that query?

Thanks,
David Ribb

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 14 Jul 2011, 08:40 AM
Hi David Ribb,

 There is no API in the context object that can provide this functionality. However this functionality is there in the IObjectScope object which you can obtain through the context. If you have an IObjectScope instance, you can call scope.Transaction.Flush() in order to have those objects in your queries but still being able to Rollback them and persist them in the database.

You can obtain an IObjectScope instance if you write a partial class for you OpenAccessContext class like the following:

public partial YourContextClass
{
     public IObjectScope Scope
     {
         get{ return this.GetScope(); }
     }
}

After adding your objects to you context, just call context.Scope.Transaction.Flush() and you will be able to have your added objects in your queries.Kind regards,
Zoran
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Getting Started
Asked by
David Ribb
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or