Created
May 10, 2018 05:03
-
-
Save markholdt/e1332ed1ea2e57dc0be569ac8e2563ba to your computer and use it in GitHub Desktop.
OrmLite String operator
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 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 Price | |
{ | |
public Guid Id { get; set; } // 'Id' is PrimaryKey by convention | |
public string PriceDate {get;set;} | |
} | |
// Delete and Recreate above schema | |
if (!db.TableExists<Price>()) | |
db.CreateTable<Price>(); // Delete ForeignKey data if exists | |
var savedPrice = new Price | |
{ | |
Id = Guid.NewGuid(), | |
PriceDate = "20180101" | |
}; | |
db.Insert(savedPrice); | |
var savedPrice2 = new Price | |
{ | |
Id = Guid.NewGuid(), | |
PriceDate = "20180102" | |
}; | |
db.Insert(savedPrice2); | |
// Load Player Record and its Referenced Data | |
var dbPlayer = db.Select<Price>(ar => ar.PriceDate <= "20180101"); | |
dbPlayer.PrintDump(); | |
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
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="ServiceStack.Text" version="5.0.2" targetFramework="net45" /> | |
<package id="ServiceStack.Client" version="5.0.2" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="5.0.2" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment