Created
June 26, 2014 09:59
-
-
Save mythz/2fd115956d57bb684787 to your computer and use it in GitHub Desktop.
Left Join in OrmLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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