コード例 #1
0
        internal T SetPrimaryKeyValue(T entity)
        {
            var primaryKey = QB <T> .GetPrimaryKeyColumns()[0];

            var newIdQuery = QB <T> .GetNewId();

            var          newId        = _dbContext.SqlConnection.Query <int>(newIdQuery, entity).Single();
            PropertyInfo propertyInfo = entity.GetType().GetProperty(Convert.ToString(primaryKey));

            propertyInfo.SetValue(entity, Convert.ChangeType(newId, propertyInfo.PropertyType), null);
            return(entity);
        }
コード例 #2
0
        public virtual void Delete(int id)
        {
            string query = QB <TEntity> .Delete();

            string primaryKey = QB <TEntity> .GetPrimaryKeyColumns().FirstOrDefault();

            var p = new DynamicParameters();

            p.Add("@" + primaryKey, id);

            if (Transaction != null)
            {
                Connection.Execute(query, p, transaction: Transaction);
            }
            else
            {
                Connection.Execute(query, p);
            }
        }