예제 #1
0
 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);
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        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;
                }
            }
        }
예제 #4
0
        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);
        }