public void Delete(Tid id) { using (IDbConnection conn = GetOpenConnection()) { string sql = string.Format(SqlDeleteFormat, Table); var param = new DynamicParameters(); param.Add(IdPropInfos.ElementAt(0).Name, id); conn.Execute(sql, param); } }
public T GetById(Tid id) { T retVal = null; using (IDbConnection conn = GetOpenConnection()) { string sql = string.Format(SqlGetByIdFormat, Table); var param = new DynamicParameters(); param.Add(IdPropInfos.ElementAt(0).Name, id); retVal = conn.Query <T>(sql, param).FirstOrDefault(); } return(retVal); }
static SingleIdRepository() { PropertyInfo idProp = IdPropInfos.ElementAt(0); foreach (var item in idProp.GetCustomAttributes()) { if (item is IdAttribute) { var attr = item as IdAttribute; idIsDbGenerated = attr.Type == IdType.DatabaseGenerated; break; } } }
public override T Create(T model) { if (idIsDbGenerated) { if (model != null) { using (IDbConnection conn = GetOpenConnection()) { string sql = string.Format(SqlCreateFormat, Table); sql += " SELECT SCOPE_IDENTITY()"; int id = conn.Query <int>(sql, model).First(); IdPropInfos.ElementAt(0).SetValue(model, id); } } } else { base.Create(model); } return(model); }