Skip to content

Instantly share code, notes, and snippets.

@gistlyn
gistlyn / data.cs
Last active October 22, 2021 09:17
SELECT SqlExpression examples
using System.Collections.Generic;
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
public class Artist
{
public int Id { get; set; }
public string Name { get; set; }
@gistlyn
gistlyn / data.cs
Last active November 10, 2020 13:33
SELECT SqlExpression with JOIN examples
using System.Collections.Generic;
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
public class Artist
{
public int Id { get; set; }
public string Name { get; set; }
@gistlyn
gistlyn / data.cs
Last active November 10, 2020 13:33
Custom SQL Examples
using System.Collections.Generic;
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
public class Artist
{
public int Id { get; set; }
public string Name { get; set; }
@gistlyn
gistlyn / data.cs
Last active November 10, 2020 13:33
Custom SQL Examples
using System.Collections.Generic;
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
public class Artist
{
public int Id { get; set; }
public string Name { get; set; }
@gistlyn
gistlyn / data.cs
Last active November 10, 2020 13:33
Dynamic Result Set Examples
using System.Collections.Generic;
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
public class Artist
{
public int Id { get; set; }
public string Name { get; set; }
@gistlyn
gistlyn / data.cs
Last active November 10, 2020 13:33
Dynamic Result Set Examples
using System.Collections.Generic;
using System.Data;
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
public class Artist
{
public int Id { get; set; }
public string Name { get; set; }
@gistlyn
gistlyn / index.md
Last active July 28, 2016 06:59
OrmLite INSERT Examples
@gistlyn
gistlyn / index.md
Last active November 10, 2022 16:56
OrmLite SELECT Examples

SELECT Examples

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

@gistlyn
gistlyn / index.md
Last active July 28, 2016 07:35
OrmLite UPDATE Examples

UPDATE Examples

In its most simple form, updating a model on its own without any filter conditions will update every field, except the Id which is used to limit the update to itself. Otherwise you can specify a custom filter condition using a typed expression:

UpdateOnly

@gistlyn
gistlyn / index.md
Last active July 28, 2016 08:13
OrmLite DELETE Examples

DELETE Examples

Deleting rows in OrmLite is simple and straight-forward with APIs to support multiple use-cases including deleting by entity, by Id, by lambda expression, by SqlExpression, or Custom SQL expression:

As well as API's for deleting all or multiple rows: