Skip to content

Instantly share code, notes, and snippets.

Last active Nov 23, 2020
What would you like to do?
Ensures with Dynamic SqlExpression Example
using ServiceStack;
using ServiceStack.Text;
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.Sqlite;
using ServiceStack.DataAnnotations;
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
var db = dbFactory.Open(); // Open ADO.NET DB Connection
OrmLiteUtils.PrintSql(); // view generated SQL
OrmLiteConfig.StripUpperInLike = true; // comment to force insensitive like comparisons
public class Table
public long Id { get; set; }
public string B { get; set; }
public int A { get; set; }
var X = new[] { "001", "002" };
var q = db.From<Table>()
.Ensure(x => x.A == 100);
foreach (var item in X)
q = q.Or(x => x.B.StartsWith(item));
var results = db.Select(q);
<?xml version="1.0" encoding="utf-8"?>
<package id="System.Memory" version="4.5.4" targetFramework="net45" />
<package id="ServiceStack.Text" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Client" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Common" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Interfaces" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.OrmLite" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.OrmLite.Sqlite.Windows" version="5.10.0" targetFramework="net45" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment