Skip to content

Instantly share code, notes, and snippets.

@Layoric Layoric/main.cs
Last active Sep 30, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.