Skip to content

Instantly share code, notes, and snippets.

@Layoric
Last active September 30, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Layoric/ca768a93b545988124cfb150a6f74ea6 to your computer and use it in GitHub Desktop.
Save Layoric/ca768a93b545988124cfb150a6f74ea6 to your computer and use it in GitHub Desktop.
LoadSelect 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
public class Foo
{
[AutoIncrement]
public int Id {get;set;}
public string Name {get;set;}
}
public class Todo
{
[AutoIncrement]
public long Id { get; set; }
public string Content { get; set; }
public int Order { get; set; }
public bool Done { get; set; }
[References(typeof(Foo))]
public int FooId { get; set; }
[Reference]
public Foo FooVal { get; set; }
}
db.CreateTable<Todo>();
db.CreateTable<Foo>();
var fooNew = new Foo {
Name = "Test"
};
db.Save(fooNew);
var newTodo = new Todo {
Content = "Learn OrmLite",
Order = 1,
FooId = 1
};
db.Save(newTodo);
var loadSelected = db.LoadSelect(db.From<Todo>().Join<Foo>().Where(x => x.FooId == 1));
"LoadSelect Todo: {0}".Print(loadSelected.Dump());
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ServiceStack.Text" version="4.5.0" targetFramework="net45" />
<package id="ServiceStack.Interfaces" version="4.5.0" targetFramework="net45" />
<package id="ServiceStack.Common" version="4.5.0" targetFramework="net45" />
<package id="ServiceStack.OrmLite" version="4.5.0" targetFramework="net45" />
<package id="ServiceStack.OrmLite.Sqlite.Mono" version="4.5.0" targetFramework="net45" />
</packages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment