public bool Save(T data, Expression <Func <T, bool> > exp, RepoOptions opts = null) { SQL <T> sql = null; IDbTransaction trans = null; if (opts != null) { sql = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields); trans = opts.DbTrans; } else { sql = this.SqlBag.AllFieldsSql; } if (trans != null) { System.Data.Common.DbConnection conn = trans?.DbConnection; System.Data.Common.DbTransaction dbTran = trans?.DbTransaction; return(sql.Save.Execute(data, exp, conn, dbTran)); } else { using (var conn = this.SqlBag.Database.CreateConnection()) { conn.Open(); return(sql.Save.Execute(data, exp, conn, null)); } } }
public async Task <T> GetAsync(Expression <Func <T, bool> > exp, RepoOptions opts = null) { SQL <T> sql = null; IDbTransaction trans = null; if (opts != null) { sql = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields); trans = opts.DbTrans; } else { sql = this.SqlBag.AllFieldsSql; } if (trans != null) { System.Data.Common.DbConnection conn = trans?.DbConnection; System.Data.Common.DbTransaction dbTran = trans?.DbTransaction; return(await sql.Get.ExecuteAsync(exp, conn, dbTran)); } else { using (var conn = this.SqlBag.Database.CreateConnection()) { await conn.OpenAsync(); return(await sql.Get.ExecuteAsync(exp, conn, null)); } } }
public bool Insert(T data, RepoOptions opts = null) { SQL <T> sql = null; IDbTransaction trans = null; if (opts != null) { sql = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields); trans = opts.DbTrans; } if (trans != null) { System.Data.Common.DbConnection conn = trans.DbConnection; System.Data.Common.DbTransaction dbTran = trans.DbTransaction; return(sql.Insert.Execute(data, conn, dbTran) == 1); } else { using (var conn = this.SqlBag.Database.CreateConnection()) { conn.Open(); return(sql.Insert.Execute(data, conn, null) == 1); } } }
public T GetById(object id, RepoOptions opts = null) { SQL <T> sql = null; IDbTransaction trans = null; if (opts != null) { sql = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields); trans = opts.DbTrans; } else { sql = this.SqlBag.AllFieldsSql; } if (trans != null) { System.Data.Common.DbConnection conn = trans?.DbConnection; System.Data.Common.DbTransaction dbTran = trans?.DbTransaction; return(sql.GetById.Execute(id, conn, dbTran)); } else { using (var conn = this.SqlBag.Database.CreateConnection()) { conn.Open(); return(sql.GetById.Execute(id, conn, null)); } } }
public async Task <List <T> > ListAsync(IFilterable <T> filtable, RepoOptions opts = null) { SQL <T> sql = null; IDbTransaction trans = null; if (opts != null) { sql = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields); trans = opts.DbTrans; } else { sql = this.SqlBag.AllFieldsSql; } if (trans != null) { System.Data.Common.DbConnection conn = trans.DbConnection; System.Data.Common.DbTransaction dbTran = trans.DbTransaction; return(await sql.Select.ExecuteAsync(filtable, conn, dbTran)); } else { using (var conn = this.SqlBag.Database.CreateConnection()) { await conn.OpenAsync(); return(await sql.Select.ExecuteAsync(filtable, conn, null)); } } }
public async Task <IPageable <T> > PageAsync(IPageable <T> pageable, RepoOptions opts = null) { var pageInfo = pageable as Pageable <T>; if (pageInfo == null) { pageInfo = new Pageable <T>(pageable); } SQL <T> sql = null; IDbTransaction trans = null; if (opts != null) { sql = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields); trans = opts.DbTrans; } else { sql = this.SqlBag.AllFieldsSql; } if (trans != null) { System.Data.Common.DbConnection conn = trans.DbConnection; System.Data.Common.DbTransaction dbTran = trans.DbTransaction; pageInfo.RecordCount = await sql.Count.ExecuteAsync(pageInfo.QueryExpression, conn, dbTran); pageInfo.Items = sql.Select.Execute(pageInfo, conn, dbTran); } else { using (var conn = this.SqlBag.Database.CreateConnection()) { await conn.OpenAsync(); pageInfo.RecordCount = await sql.Count.ExecuteAsync(pageInfo.QueryExpression, conn, null); pageInfo.Items = await sql.Select.ExecuteAsync(pageInfo, conn, null); } } return(pageInfo); }