Replace:

	bool exists = SqlHelper.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId",
                                       SqlHelper.CreateParameter("@nodeId", _media.Id)) > 0;

with

            bool exists = ApplicationContext.Current.DatabaseContext.Database.SingleOrDefault<int>(
                "SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId", new { nodeId = _media.Id }) > 0;