OpenAccessDomainService Executing OQL query is very slow

2 posts, 0 answers
  1. Jacek
    Jacek avatar
    6 posts
    Member since:
    Dec 2012

    Posted 06 Apr Link to this post

    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.}

  2. Jacek
    Jacek avatar
    6 posts
    Member since:
    Dec 2012

    Posted 07 Apr in reply to Jacek Link to this post

    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();

  3. DevCraft banner
Back to Top