Created
January 6, 2013 08:44
-
-
Save rcurlette/4466118 to your computer and use it in GitHub Desktop.
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 System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using ServiceStack.OrmLite; | |
using ServiceStack.OrmLite.Sqlite; | |
using System.Data; | |
using ServiceStack.Common.Utils; | |
namespace OrmLiteExample | |
{ | |
class Program | |
{ | |
// Updated using excellent feedback from Demis Bellot | |
public static string SqliteMemoryDb = ":memory:"; | |
public static string SqliteFileDb = "~/App_Data/db.sqlite".MapAbsolutePath(); | |
static void Main(string[] args) | |
{ | |
//Using Sqlite DB | |
var dbFactory = new OrmLiteConnectionFactory( | |
SqliteFileDb, false, SqliteDialect.Provider); | |
using (var db = dbFactory.Open()) { | |
db.CreateTableIfNotExists<Note>(); | |
// Insert | |
db.Insert( | |
new Note { | |
SchemaUri = "tcm:0-0-0", | |
NoteText = "Hello world 5", | |
LastUpdated = new DateTime(2013, 1, 5), | |
UpdatedBy = "RC" }); | |
// Read | |
var notes = db.Where<Note>(new { SchemaUri = "tcm:0-0-0" }); | |
foreach (Note note in notes) | |
{ | |
Console.WriteLine("note id=" + note.Id + "noteText=" + note.NoteText); | |
} | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment