Skip to content

Instantly share code, notes, and snippets.

@mythz
Created June 26, 2014 09:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/2fd115956d57bb684787 to your computer and use it in GitHub Desktop.
Save mythz/2fd115956d57bb684787 to your computer and use it in GitHub Desktop.
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