Created
March 10, 2017 12:38
-
-
Save xplicit/25132e405496c04e97cbafb0745a9941 to your computer and use it in GitHub Desktop.
OrmLite Join
This file contains hidden or 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 Todo | |
{ | |
[AutoIncrement] | |
public long Id { get; set; } | |
public string Content { get; set; } | |
public int Order { get; set; } | |
public bool Done { get; set; } | |
} | |
db.CreateTable<Todo>(); | |
var newTodo = new Todo { | |
Content = "Learn OrmLite", | |
Order = 1 | |
}; | |
db.Save(newTodo); | |
var savedTodo = db.SingleById<Todo>(newTodo.Id); | |
"Saved Todo: {0}".Print(savedTodo.Dump()); | |
savedTodo.Done = true; | |
db.Update(savedTodo); | |
var updatedTodo = db.SingleById<Todo>(newTodo.Id); | |
"Updated Todo: {0}".Print(updatedTodo.Dump()); | |
db.DeleteById<Todo>(newTodo.Id); | |
var remainingTodos = db.Select<Todo>(); | |
"No more Todos: {0}".Print(remainingTodos.Dump()); |
This file contains hidden or 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