Search code examples
linqsqlitexamarinsql-order-bymvvmcross

linq query 'orderby' using multiple fields at SQLite plugin by MvvmCross doesn't work


The query is the following:

var query = from c in _db.Table<Contact>()
            where c.FirstName.Contains("Alex")
            orderby c.Priority, c.FirstName, c.LastName
            select c;

Is it a limitation of SQLite, MvvmCross plugin? Should I go with .Syntax as a result?

Error CS1936: An implementation of `ThenBy' query expression pattern for source type `Cirrious.MvvmCross.Community.Plugins.Sqlite.ITableQuery<Contact>' could not be found (CS1936)

Solution

  • I was able to handle this by specifying mutiple OrderBy methods:

    var res = _db.Table<Contact>()
     .Where(c=> c.....)
     .OrderBy(c => c.Priority)
     .OrderBy(c => c.FirstName)
     .OrderBy(c => c.LastName)
     .Select(c=> c)
     .ToList();
    

    Translated to the SQLite query:

    SELECT * FROM "Contact"
    WHERE ...
    ORDER BY "Priority", "FirstName", "LastName"
    

    Hope this helped