Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Left Join in OrmLite
using System;
using ServiceStack.OrmLite;
using ServiceStack.Text;
namespace ConsoleApplication2
{
public class TableA
{
public int Id { get; set; }
public string Name { get; set; }
}
public class TableB
{
public int AId { get; set; }
public string PostCode { get; set; }
public string Value { get; set; }
}
public class TableABFields
{
public string TableAName { get; set; }
public string TableBValue { get; set; }
}
class Program
{
static void Main(string[] args)
{
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
using (var db = dbFactory.Open())
{
db.DropAndCreateTable<TableA>();
db.DropAndCreateTable<TableB>();
db.DropAndCreateTable<TableABFields>();
db.Insert(new TableA { Id = 1, Name = "Foo" });
db.Insert(new TableB { AId = 1, Value = "Foo", PostCode = "12345" });
var q = OrmLiteConfig.DialectProvider.SqlExpression<TableA>();
q.Join<TableA, TableB>((a, b) => b.AId == a.Id && b.PostCode == "12345");
var results = db.Select(q);
results.PrintDump();
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment