Skip to content

Instantly share code, notes, and snippets.

@mythz mythz/main.cs
Created Mar 30, 2019

What would you like to do?
Custom Self Reference Conventions
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 CustomerAddress
public int Id { get; set; }
public string Address { get; set; }
public string Country { get; set; }
public class Customer
public int Id { get; set; }
public string Name { get; set; }
public int Id_PrimaryAddress { get; set; } // with a prefix
public CustomerAddress PrimaryAddress { get; set; }
var customer = new Customer
Name = "The Customer",
PrimaryAddress = new CustomerAddress {
Address = "1 Home Street",
Country = "US"
db.Save(customer, references:true);
var c = db.LoadSelect<Customer>(x => x.Name == "The Customer");
<?xml version="1.0" encoding="utf-8"?>
<package id="ServiceStack.Text" version="5.2.0" targetFramework="net45" />
<package id="ServiceStack.Interfaces" version="5.2.0" targetFramework="net45" />
<package id="ServiceStack.Common" version="5.2.0" targetFramework="net45" />
<package id="ServiceStack.OrmLite" version="5.2.0" targetFramework="net45" />
<package id="ServiceStack.OrmLite.Sqlite.Windows" version="5.2.0" targetFramework="net45" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.