OrmLite has extensive support for Querying exposing an intuitive 1:1 Typed API that maps cleanly and has a high affinity with SQL that's not only natural to write but also easy to predict what SQL it generates.
For simple queries you can use terse lambda Expressions to specify the filter conditions you want:
For more advanced queries you can leverage the SqlExpression
builder which provides a Typed API that closely follows
SQL except it's created by calling db.From<T>
with the table you want to query and optionally ends with a
Custom .Select()
if you want to customize the resultset that's returned (similar to LINQ). Some examples of
SqlExpression in action:
Just like SQL, SqlExpression supports multiple JOIN's that can leverage OrmLite's Reference Conventions for Simple, Terse and Intuitive Table JOIN's:
In addition to db.Select()
OrmLite provides a number of other convenience API's to return results for your
preferred use-case:
In addition there are convenience API's to return results in your preferred .NET Collection:
If you need more flexibility or RDBMS-specific functionality that's not possible using Typed APIs you can drop down to raw SQL using our Custom SQL APIs:
Whilst OrmLite is predominantly a typed code-first ORM it also offers several options for reading unstructured results when the Schema is unknown or unavailable: