Last active
December 10, 2015 15:08
-
-
Save rcurlette/4451872 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 | |
{ | |
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