Query context with added but not saved entities

2 posts, 0 answers
  1. David Ribb
    David Ribb avatar
    16 posts
    Member since:
    Aug 2012

    Posted 09 Jul 2011 Link to this post

    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
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 14 Jul 2011 Link to this post

    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!

  3. DevCraft banner
Back to Top