Last active
May 9, 2017 05:49
-
-
Save mythz/41382a607a946e647e1960b664f729a3 to your computer and use it in GitHub Desktop.
Image Place demo
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 | |
[Alias("Places")] | |
public class Place | |
{ | |
public Guid Id { get; set; } | |
[Reference] | |
public List<Image> Countries { get; set; } | |
} | |
[Alias("Images")] | |
public class Image | |
{ | |
public Guid Id { get; set; } | |
//[Alias("ColumnAliasIfNotPlaceId")] | |
public Guid PlaceId { get; set; } | |
public string Url { get; set; } //Example field on Image | |
} | |
db.CreateTable<Place>(); | |
db.CreateTable<Image>(); | |
var placeId = Guid.NewGuid(); | |
var place = new Place | |
{ | |
Id = placeId, | |
Countries = new List<Image> { | |
new Image { Id = Guid.NewGuid(), PlaceId = placeId, Url = "http://url.to/country1.png" }, | |
new Image { Id = Guid.NewGuid(), PlaceId = placeId, Url = "http://url.to/country2.png" }, | |
} | |
}; | |
db.Save(place, references: true); | |
var fromDb = db.LoadSingleById<Place>(placeId); | |
fromDb.PrintDump(); | |
"Images Only:\n{0}".Print(db.Select<Image>(x => x.PlaceId == placeId).Dump()); |
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="4.5.8" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="4.5.8" targetFramework="net45" /> | |
<package id="ServiceStack.Common" version="4.5.8" targetFramework="net45" /> | |
<package id="ServiceStack.OrmLite" version="4.5.8" targetFramework="net45" /> | |
<package id="ServiceStack.OrmLite.Sqlite.Mono" version="4.5.8" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment