Last active
November 10, 2020 13:35
-
-
Save gistlyn/bcff262634aa255d5ef4a2e4fb424391 to your computer and use it in GitHub Desktop.
Modify Table Schema Examples
This file contains hidden or 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 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(); | |
public class Track | |
{ | |
[AutoIncrement] | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Album { get; set; } | |
public int ArtistId { get; set; } | |
} | |
[Alias("Track")] // Map to same "Track" RDBMS Table, not needed when Track is refactored | |
public class Track_v2 | |
{ | |
[AutoIncrement] | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Album { get; set; } | |
public int ArtistId { get; set; } | |
[Default(5)] | |
public int Rating { get; set; } // ADD | |
} | |
bool v1TableExists, v2TableExists, v1RatingExists, v2RatingExists; | |
v1TableExists = db.TableExists<Track>(); | |
"Table Exists: {0}".Print(v1TableExists); | |
if (!v1TableExists) | |
{ | |
db.CreateTable<Track>(); | |
v1TableExists = db.TableExists<Track>(); | |
"Table Exists v1: {0}".Print(v1TableExists); | |
} | |
v1RatingExists = db.ColumnExists<Track_v2>(x => x.Rating); | |
"Rating Exists v1: {0}".Print(v1RatingExists); | |
if (!v1RatingExists) | |
{ | |
db.AddColumn<Track_v2>(x => x.Rating); | |
v2RatingExists = db.ColumnExists<Track_v2>(x => x.Rating); | |
"Rating Exists v2: {0}".Print(v2RatingExists); | |
} |
This file contains hidden or 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="System.Memory" version="4.5.4" targetFramework="net45" /> | |
<package id="ServiceStack.Text" version="5.10.0" targetFramework="net45" /> | |
<package id="ServiceStack.Client" version="5.10.0" targetFramework="net45" /> | |
<package id="ServiceStack.Common" version="5.10.0" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="5.10.0" targetFramework="net45" /> | |
<package id="ServiceStack.OrmLite" version="5.10.0" targetFramework="net45" /> | |
<package id="ServiceStack.OrmLite.Sqlite.Windows" version="5.10.0" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment