<# if (string.IsNullOrEmpty(Namespace)) Namespace=ConnectionStringName; if (string.IsNullOrEmpty(RepoName) && !string.IsNullOrEmpty(ConnectionStringName)) RepoName=ConnectionStringName + "DB"; if (string.IsNullOrEmpty(Namespace)) Namespace="PetaPoco"; if (string.IsNullOrEmpty(RepoName)) RepoName="PetaPocoDB"; #> using System; using System.Collections.Generic; using System.Linq; using System.Web; using PetaPoco; namespace <#=Namespace #> { <# if (GenerateCommon) { #> public partial class <#=RepoName#> : Database { public <#=RepoName#>() : base("<#=ConnectionStringName#>") { CommonConstruct(); } public <#=RepoName#>(string connectionStringName) : base(connectionStringName) { CommonConstruct(); } partial void CommonConstruct(); public interface IFactory { <#=RepoName#> GetInstance(); } public static IFactory Factory { get; set; } public static <#=RepoName#> GetInstance() { if (_instance!=null) return _instance; if (Factory!=null) return Factory.GetInstance(); else return new <#=RepoName#>(); } [ThreadStatic] static <#=RepoName#> _instance; public override void OnBeginTransaction() { if (_instance==null) _instance=this; } public override void OnEndTransaction() { if (_instance==this) _instance=null; } <# if (GenerateOperations) { #> public class Record where T:new() { public static <#=RepoName#> repo { get { return <#=RepoName#>.GetInstance(); } } public bool IsNew() { return repo.IsNew(this); } public void Save() { repo.Save(this); } public object Insert() { return repo.Insert(this); } public int Update() { return repo.Update(this); } public int Delete() { return repo.Delete(this); } public static int Update(string sql, params object[] args) { return repo.Update(sql, args); } public static int Update(Sql sql) { return repo.Update(sql); } public static int Delete(string sql, params object[] args) { return repo.Delete(sql, args); } public static int Delete(Sql sql) { return repo.Delete(sql); } public static int Delete(object primaryKey) { return repo.Delete(primaryKey); } public static bool Exists(object primaryKey) { return repo.Exists(primaryKey); } public static T SingleOrDefault(object primaryKey) { return repo.SingleOrDefault(primaryKey); } public static T SingleOrDefault(string sql, params object[] args) { return repo.SingleOrDefault(sql, args); } public static T SingleOrDefault(Sql sql) { return repo.SingleOrDefault(sql); } public static T FirstOrDefault(string sql, params object[] args) { return repo.FirstOrDefault(sql, args); } public static T FirstOrDefault(Sql sql) { return repo.FirstOrDefault(sql); } public static T Single(object primaryKey) { return repo.Single(primaryKey); } public static T Single(string sql, params object[] args) { return repo.Single(sql, args); } public static T Single(Sql sql) { return repo.Single(sql); } public static T First(string sql, params object[] args) { return repo.First(sql, args); } public static T First(Sql sql) { return repo.First(sql); } public static List Fetch(string sql, params object[] args) { return repo.Fetch(sql, args); } public static List Fetch(Sql sql) { return repo.Fetch(sql); } public static List Fetch(long page, long itemsPerPage, string sql, params object[] args) { return repo.Fetch(page, itemsPerPage, sql, args); } public static List Fetch(long page, long itemsPerPage, Sql sql) { return repo.Fetch(page, itemsPerPage, sql); } public static Page Page(long page, long itemsPerPage, string sql, params object[] args) { return repo.Page(page, itemsPerPage, sql, args); } public static Page Page(long page, long itemsPerPage, Sql sql) { return repo.Page(page, itemsPerPage, sql); } public static IEnumerable Query(string sql, params object[] args) { return repo.Query(sql, args); } public static IEnumerable Query(Sql sql) { return repo.Query(sql); } } <# } #> } <# } #> <# if (GeneratePocos) { #> <# foreach(Table tbl in from t in tables where !t.Ignore select t) { #> [TableName("<#=tbl.Name#>")] <# if (tbl.PK!=null && tbl.PK.IsAutoIncrement) { #> <# if (tbl.SequenceName==null) { #> [PrimaryKey("<#=tbl.PK.Name#>")] <# } else { #> [PrimaryKey("<#=tbl.PK.Name#>", sequenceName="<#=tbl.SequenceName#>")] <# } #> <# } #> <# if (tbl.PK!=null && !tbl.PK.IsAutoIncrement) { #> [PrimaryKey("<#=tbl.PK.Name#>", autoIncrement=false)] <# } #> [ExplicitColumns] public partial class <#=tbl.ClassName#> <# if (GenerateOperations) { #>: <#=RepoName#>.Record<<#=tbl.ClassName#>> <# } #> { <# foreach(Column col in from c in tbl.Columns where !c.Ignore select c) { // Column bindings #> <# if (col.Name!=col.PropertyName) { #> [Column("<#=col.Name#>")] public <#=col.PropertyType #><#=CheckNullable(col)#> <#=col.PropertyName #> { get; set; } <# } else { #> [Column] public <#=col.PropertyType #><#=CheckNullable(col)#> <#=col.PropertyName #> { get; set; } <# } #> <# } #> } <# } #> <# } #> }