This question is locked. New answers and comments are not allowed.
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.
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.
4 Answers, 1 is accepted
0
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:
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.
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.
0
Sigurd
Top achievements
Rank 1
answered on 19 Jun 2009, 10:02 AM
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?
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?
0
Accepted
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.
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.
0
Sigurd
Top achievements
Rank 1
answered on 22 Jun 2009, 06:26 AM
Thanks!