Skip to content

Instantly share code, notes, and snippets.

@rcurlette
Created January 6, 2013 08:44
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 rcurlette/4466118 to your computer and use it in GitHub Desktop.
Save rcurlette/4466118 to your computer and use it in GitHub Desktop.
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