Search code examples
telerikdata-accessdomain-modeldomainservicestelerik-open-access

OpenAccessDomainService Executing OQL query is very slow


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:

[EnableClientAccess()]
public partial class ZooDomainService : OpenAccessDomainService<Model.ZooDomainModel>
{
    public ZooDomainService() : base()
    {
    }


    /// <param name="stringQuery">eg. AND (r.type = "Elephant" OR r.type = "Monkey") ORDER BY r.id ASC</param>
    public IQueryable<Animals> getAnimalsLazy(string stringQuery, int range, int page)
    {
        stringQuery = "SELECT r FROM AnimalsExtent AS r WHERE true " + stringQuery;

        Database db = Database.Get("Connection");
        IObjectScope scope = db.GetObjectScope();
        Query<Animals> qry = scope.GetOqlQuery<Animals>(stringQuery);

        int toSkip = (page - 1) * range;
        qry.Skip = toSkip;
        qry.MaxResultCount = range;

        return qry.ExecuteEnumerable().AsQueryable<Animals>();
    }

    public IQueryable<Animals> getAnimals()
    {
        return this.DataContext.Animals;
    }
}

Solution

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

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