예제 #1
0
        public void SaveOrUpdate <T>(T entity, int?parentId) where T : class, IEntity, new()
        {
            var entityMap = domainMap.GetMapFor <T>();

            if (entity.IsTransient)
            {
                var commandSpec = entityMap.GetInsertCommand(entity, parentId);
                ExecuteNonQuery(commandSpec);
                var getIdCommandSpec = dbAdapter.CreateLastInsertIdCommand();
                var getIdCommand     = getIdCommandSpec.CreateCommand(dbAdapter, connection);
                var result           = getIdCommand.ExecuteScalar();
                var id = Convert.ToInt32(result);
                entity.SetId(id);
            }
            else
            {
                ExecuteNonQuery(entityMap.GetUpdateCommand(entity, parentId));
            }
            Cascade(entityMap, entity);
        }