Skip to content

Instantly share code, notes, and snippets.

@rcurlette
Last active December 10, 2015 15:08
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/4451872 to your computer and use it in GitHub Desktop.
Save rcurlette/4451872 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
{
public static string SqliteMemoryDb = ":memory:";
// Updated per comment form Jonas.
//First connection string below causes an app pool restart! Use MapHostAbsolutePath instead!
//public static string SqliteFileDb = "~/App_Data/db.sqlite".MapAbsolutePath();
public static string SqliteFileDb = "~/App_Data/db.sqlite".MapHostAbsolutePath();
static void Main(string[] args)
{
//Using Sqlite DB
var dbFactory = new OrmLiteConnectionFactory(
SqliteFileDb, false, SqliteOrmLiteDialectProvider.Instance);
//Non-intrusive: All extension methods hang off System.Data.* interfaces
IDbConnection dbConn = dbFactory.OpenDbConnection();
IDbCommand dbCmd = dbConn.CreateCommand();
// Create table - will this be not be created if it exists
dbConn.CreateTable<Note>();
// Insert
dbConn.Insert(new Note { SchemaUri = "tcm:0-0-0", NoteText = "Hello world 5", LastUpdated = new DateTime(2013, 1, 5), UpdatedBy = "RC" });
// Read
var notes = dbConn.Select<Note>("SchemaUri='tcm:0-0-0'");
foreach (Note note in notes)
{
Console.WriteLine("note id=" + note.Id + "noteText=" + note.NoteText);
}
Console.ReadLine();
dbConn.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment