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

OpenAccessDomainService Executing OQL query is very slow

1 Answer 50 Views
OQL (OQL specific 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.
Jacek
Top achievements
Rank 1
Jacek asked on 06 Apr 2016, 02:39 PM

Hello, I have big problem with OQL query in OpenAccessDomainService.

I have application with Silverlight client and RIA Web Service (OpenAccessDomainService), and I need to implement lazy loading approach.

For example I created method getAnimalsLazy(string stringQuery, int range, int page) where I can pass stringQuery from filters, records per page and page. This methods works fine but is dramatically slow.

To compare it I created method getAnimals() which is so fast, it is loading 15 000 records in ~4 sec. When I run getAnimalsLazy it is loading 25 records in ~2 sec.

I don't know what I am doing wrong, could somebody help me.

 

This is example code:

 

01.[EnableClientAccess()]
02.public partial class ZooDomainService : OpenAccessDomainService<Model.ZooDomainModel>
03.{
04.        public ZooDomainService() : base()
05.        {
06.        }
07. 
08. 
09.        /// <param name="stringQuery">eg. AND (r.type = "Elephant" OR r.type = "Monkey") ORDER BY r.id ASC</param>
10.        public IQueryable<Animals> getAnimalsLazy(string stringQuery, int range, int page)
11.        {
12.            stringQuery = "SELECT r FROM AnimalsExtent AS r WHERE true " + stringQuery;
13. 
14.            Database db = Database.Get("Connection");
15.            IObjectScope scope = db.GetObjectScope();
16.            Query<Animals> qry = scope.GetOqlQuery<Animals>(stringQuery);
17. 
18.            int toSkip = (page - 1) * range;
19.            qry.Skip = toSkip;
20.            qry.MaxResultCount = range;
21. 
22.            return qry.ExecuteEnumerable().AsQueryable<Animals>();
23.        }
24. 
25.        public IQueryable<Animals> getAnimals()
26.        {
27.            return this.DataContext.Animals;
28.        }
29.}

1 Answer, 1 is accepted

Sort by
0
Jacek
Top achievements
Rank 1
answered on 07 Apr 2016, 08:14 AM

I found solution of my problem when I refactor getAnimalsLazy with this.DataContext.ExecuteQuery(queryString) everything works fine.

1.stringQuery = "SELECT * FROM animals AS r WHERE true ORDER BY r.id ASC LIMIT 25 OFFSET 0";
2.return this.DataContext.ExecuteQuery<Animals>(stringQuery).AsQueryable();

Tags
OQL (OQL specific questions)
Asked by
Jacek
Top achievements
Rank 1
Answers by
Jacek
Top achievements
Rank 1
Share this question
or