Syncronizing list and scope

Thread is closed for posting
5 posts, 1 answers
  1. Sigurd
    Sigurd avatar
    5 posts
    Member since:
    Dec 2008

    Posted 18 Jun 2009 Link to this post

    I get a list of entities by oql query, for example
    Query<Human> q = scope.GetOqlQuery<Human>("select hum from HumanExtent as hum");
    QueryResultBindingList<Human> qr = q.ExecuteBindingList();

    Then I bind this list to GridView via BindingSource component.
    humanBindingSource.DataSource = qr;

    In other place I create an entity instance and add it to the scope, for example
     Human h = new Human();
    ..........
    scope.add(h);

    After these actions I wanna have  qr  list with new added entity instance without repeated query. Does any way exist to do it?
    Thanks.
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 19 Jun 2009 Link to this post

    Hello Sigurd,

    I am afraid this in not possible with a query result. This binding list is populated only when the query is being executed. So you will have to execute it again to get the latest results. Just a little tip here, when the OQL statement does not contain any conditions, you can create the query without specifying an OQL statement at all:
    Query<Human> q = scope.GetOqlQuery<Human>(); 

    To achieve the auto-refresh functionality you can use an OpenAccessDataSource for web or ObjectProvider/ObjectView for Windows forms applications. Then if you add an object to the datasource, the Grid will refresh itself automatically.

    Regards,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Sigurd
    Sigurd avatar
    5 posts
    Member since:
    Dec 2008

    Posted 19 Jun 2009 Link to this post

    I have yet another question. The following code had been executed normally:

                IObjectScope sc = ObjectProvider.ObjectScope();
                sc.Transaction.Begin();
                Query<Human> qr = sc.GetOqlQuery<Human>();
                IList<Human> humans = qr.ExecuteBindingList();
                .......
                 Human human = new Human();
                 .........
                 humans.Add(human);
                .........
                sc.Transaction.Commit();
                All works fine and new instance was added to database after commit.

               But in this case:
             
               IObjectScope sc = ObjectProvider.ObjectScope();
                sc.Transaction.Begin();
                Query<Human> qr = sc.GetOqlQuery<Human>();
                IList<Human> humans = qr.ExecuteBindingList();
                ........
                var curr = humanBindingSource.Current as Human;
                humans.Remove(curr);
                .........
                sc.Transaction.Commit();
                the Human instance was succefully removed from list but after commit it wasn't deleted from database! Why?
            
            
  4. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 19 Jun 2009 Link to this post

    Hi Sigurd,

    You are calling the IList.Remove() method and that is why the objects is removed from the list. However, to remove it from the database you have to execute scope.Remove(curr). Then the object will be deleted.

    Kind regards,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Sigurd
    Sigurd avatar
    5 posts
    Member since:
    Dec 2008

    Posted 22 Jun 2009 Link to this post

    Thanks!
Back to Top