Last active
September 30, 2016 08:21
-
-
Save Layoric/ca768a93b545988124cfb150a6f74ea6 to your computer and use it in GitHub Desktop.
LoadSelect Example
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 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()); | |
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
<?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