diff --git a/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs
index 7526d83cd0..9902c8df30 100644
--- a/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/IDocumentVersionRepository.cs
@@ -7,17 +7,17 @@ public interface IDocumentVersionRepository : IRepository
///
/// Gets a list of all historic content versions.
///
- public IReadOnlyCollection? GetDocumentVersionsEligibleForCleanup();
+ public IReadOnlyCollection GetDocumentVersionsEligibleForCleanup();
///
/// Gets cleanup policy override settings per content type.
///
- public IReadOnlyCollection? GetCleanupPolicies();
+ public IReadOnlyCollection GetCleanupPolicies();
///
/// Gets paginated content versions for given content id paginated.
///
- public IEnumerable? GetPagedItemsByContentId(int contentId, long pageIndex, int pageSize, out long totalRecords, int? languageId = null);
+ public IEnumerable GetPagedItemsByContentId(int contentId, long pageIndex, int pageSize, out long totalRecords, int? languageId = null);
///
/// Deletes multiple content versions by ID.
diff --git a/src/Umbraco.Core/Security/ExternalLoginToken.cs b/src/Umbraco.Core/Security/ExternalLoginToken.cs
index df986d176f..c2b93caa84 100644
--- a/src/Umbraco.Core/Security/ExternalLoginToken.cs
+++ b/src/Umbraco.Core/Security/ExternalLoginToken.cs
@@ -3,6 +3,8 @@ namespace Umbraco.Cms.Core.Security;
///
public class ExternalLoginToken : IExternalLoginToken
{
+ public const string TableName = Constants.DatabaseSchema.Tables.ExternalLoginToken;
+
///
/// Initializes a new instance of the class.
///
diff --git a/src/Umbraco.Core/Services/ContentVersionService.cs b/src/Umbraco.Core/Services/ContentVersionService.cs
index 5dddaad709..230aa22126 100644
--- a/src/Umbraco.Core/Services/ContentVersionService.cs
+++ b/src/Umbraco.Core/Services/ContentVersionService.cs
@@ -79,7 +79,7 @@ internal sealed class ContentVersionService : IContentVersionService
return Task.FromResult(Attempt?, ContentVersionOperationStatus>.Fail(ContentVersionOperationStatus.InvalidSkipTake));
}
- IEnumerable? versions =
+ IEnumerable versions =
HandleGetPagedContentVersions(
document.Id,
pageNumber,
@@ -87,11 +87,6 @@ internal sealed class ContentVersionService : IContentVersionService
out var total,
culture);
- if (versions is null)
- {
- return Task.FromResult(Attempt?, ContentVersionOperationStatus>.Fail(ContentVersionOperationStatus.NotFound));
- }
-
return Task.FromResult(Attempt?, ContentVersionOperationStatus>.Succeed(
ContentVersionOperationStatus.Success, new PagedModel(total, versions)));
}
@@ -152,8 +147,12 @@ internal sealed class ContentVersionService : IContentVersionService
}
}
- private IEnumerable? HandleGetPagedContentVersions(int contentId, long pageIndex,
- int pageSize, out long totalRecords, string? culture = null)
+ private IEnumerable HandleGetPagedContentVersions(
+ int contentId,
+ long pageIndex,
+ int pageSize,
+ out long totalRecords,
+ string? culture = null)
{
using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true))
{
@@ -221,18 +220,20 @@ internal sealed class ContentVersionService : IContentVersionService
*/
using (ICoreScope scope = _scopeProvider.CreateCoreScope())
{
- IReadOnlyCollection? allHistoricVersions =
+ IReadOnlyCollection allHistoricVersions =
_documentVersionRepository.GetDocumentVersionsEligibleForCleanup();
- if (allHistoricVersions is null)
+ if (allHistoricVersions.Count == 0)
{
scope.Complete();
return Array.Empty();
}
- if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
+
+ if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("Discovered {count} candidate(s) for ContentVersion cleanup", allHistoricVersions.Count);
}
+
versionsToDelete = new List(allHistoricVersions.Count);
IEnumerable filteredContentVersions =
@@ -245,7 +246,7 @@ internal sealed class ContentVersionService : IContentVersionService
if (scope.Notifications.PublishCancelable(
new ContentDeletingVersionsNotification(version.ContentId, messages, version.VersionId)))
{
- if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
+ if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("Delete cancelled for ContentVersion [{versionId}]", version.VersionId);
}
@@ -260,7 +261,7 @@ internal sealed class ContentVersionService : IContentVersionService
if (!versionsToDelete.Any())
{
- if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
+ if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("No remaining ContentVersions for cleanup");
}
diff --git a/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs b/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs
index 234dae683f..51813c3163 100644
--- a/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs
+++ b/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs
@@ -35,7 +35,7 @@ public class DefaultContentVersionCleanupPolicy : IContentVersionCleanupPolicy
using (ICoreScope scope = _scopeProvider.CreateCoreScope())
{
- var policyOverrides = _documentVersionRepository.GetCleanupPolicies()?
+ var policyOverrides = _documentVersionRepository.GetCleanupPolicies()
.ToDictionary(x => x.ContentTypeId);
foreach (ContentVersionMeta version in items)
diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs
index baf77377f8..acb86aea72 100644
--- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs
+++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs
@@ -117,7 +117,10 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install
{
// found only 1 user == the default user with default password
// however this always exists on uCloud, also need to check if there are other users too
- result = _scopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoUser");
+ sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql()
+ .SelectCount()
+ .From();
+ result = _scopeAccessor.AmbientScope.Database.ExecuteScalar(sql);
has = result != 1;
}
scope.Complete();
diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs
index 4174196cad..0b1417f699 100644
--- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs
+++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs
@@ -9,7 +9,9 @@ using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
+using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
+using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.Migrations.Install;
@@ -1828,7 +1830,7 @@ internal sealed class DatabaseDataCreator
};
_database.Insert(Constants.DatabaseSchema.Tables.Language, "id", false, dto);
isDefault = false;
- id++;
+ id += 1;
}
}
else
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs
index cfde523e28..9558b7e6c1 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Access)]
+[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class AccessDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Access;
+
[Column("id")]
[PrimaryKeyColumn(Name = "PK_umbracoAccess", AutoIncrement = false)]
public Guid Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs
index ae0e654bd2..f6d97c72b0 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs
@@ -5,11 +5,12 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.AccessRule)]
+[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class AccessRuleDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.AccessRule;
[Column("id")]
[PrimaryKeyColumn(Name = "PK_umbracoAccessRule", AutoIncrement = false)]
public Guid Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/AuditEntryDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/AuditEntryDto.cs
index e8d8a2052c..cc88e37f18 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/AuditEntryDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/AuditEntryDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.AuditEntry)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal sealed class AuditEntryDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.AuditEntry;
+
[Column("id")]
[PrimaryKeyColumn]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs
index bc4babef95..0c274c3195 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.CacheInstruction)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
public class CacheInstructionDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.CacheInstruction;
+
[Column("id")]
[NullSetting(NullSetting = NullSettings.NotNull)]
[PrimaryKeyColumn(AutoIncrement = true, Name = "PK_umbracoCacheInstruction")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ConsentDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ConsentDto.cs
index e205869c56..6445f992e8 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ConsentDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ConsentDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Consent)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
public class ConsentDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Consent;
+
[Column("id")]
[PrimaryKeyColumn]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs
index 21e94349bd..d9a03c644f 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs
@@ -17,17 +17,17 @@ public class ContentDto
public int NodeId { get; set; }
[Column("contentTypeId")]
- [ForeignKey(typeof(ContentTypeDto), Column = "NodeId")]
+ [ForeignKey(typeof(ContentTypeDto), Column = "nodeId")]
public int ContentTypeId { get; set; }
[ResultColumn]
- [Reference(ReferenceType.OneToOne, ColumnName = "NodeId")]
+ [Reference(ReferenceType.OneToOne, ColumnName = "nodeId")]
public NodeDto NodeDto { get; set; } = null!;
// although a content has many content versions,
// they can only be loaded one by one (as several content),
// so this here is a OneToOne reference
[ResultColumn]
- [Reference(ReferenceType.OneToOne, ReferenceMemberName = "NodeId")]
+ [Reference(ReferenceType.OneToOne, ReferenceMemberName = "nodeId")]
public ContentVersionDto ContentVersionDto { get; set; } = null!;
}
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs
index a3a978f2e4..2ec2977671 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs
@@ -5,7 +5,7 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.NodeData)]
+[TableName(TableName)]
[PrimaryKey("nodeId", AutoIncrement = false)]
[ExplicitColumns]
public class ContentNuDto
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentType2ContentTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentType2ContentTypeDto.cs
index e4c4bf77de..a8d8a28864 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentType2ContentTypeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentType2ContentTypeDto.cs
@@ -4,10 +4,12 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.ContentTypeTree)]
+[TableName(TableName)]
[ExplicitColumns]
internal sealed class ContentType2ContentTypeDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.ContentTypeTree;
+
[Column("parentContentTypeId")]
[PrimaryKeyColumn(AutoIncrement = false, Clustered = true, Name = "PK_cmsContentType2ContentType", OnColumns = "parentContentTypeId, childContentTypeId")]
[ForeignKey(typeof(NodeDto), Name = "FK_cmsContentType2ContentType_umbracoNode_parent")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs
index 5f0bf8f608..95d2feec3d 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.ContentChildType)]
+[TableName(TableName)]
[PrimaryKey("Id", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class ContentTypeAllowedContentTypeDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.ContentChildType;
+
[Column("Id")]
[ForeignKey(typeof(ContentTypeDto), Name = "FK_cmsContentTypeAllowedContentType_cmsContentType", Column = "nodeId")]
[PrimaryKeyColumn(AutoIncrement = false, Clustered = true, Name = "PK_cmsContentTypeAllowedContentType", OnColumns = "Id, AllowedId")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs
index 4239937d21..fd85047891 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.DocumentType)]
+[TableName(TableName)]
[PrimaryKey("contentTypeNodeId", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class ContentTypeTemplateDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.DocumentType;
+
[Column("contentTypeNodeId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_cmsDocumentType", OnColumns = "contentTypeNodeId, templateNodeId")]
[ForeignKey(typeof(ContentTypeDto), Column = "nodeId")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs
index 254ffc2e2a..9e8b4dee22 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs
@@ -4,11 +4,12 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.DataType)]
+[TableName(TableName)]
[PrimaryKey("nodeId", AutoIncrement = false)]
[ExplicitColumns]
public class DataTypeDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.DataType;
[Column("nodeId")]
[PrimaryKeyColumn(AutoIncrement = false)]
[ForeignKey(typeof(NodeDto))]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs
index e50ed28de6..b78538f349 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs
@@ -1,4 +1,4 @@
-using NPoco;
+using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
@@ -9,7 +9,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
[ExplicitColumns]
public class DocumentDto
{
- private const string TableName = Constants.DatabaseSchema.Tables.Document;
+ public const string TableName = Constants.DatabaseSchema.Tables.Document;
// Public constants to bind properties between DTOs
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs
index 028eb0f52a..7a9257423f 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs
@@ -6,7 +6,7 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.KeyValue)]
+[TableName(TableName)]
[PrimaryKey("key", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class KeyValueDto
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/LogViewerQueryDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/LogViewerQueryDto.cs
index c71cb9b6b3..2420996879 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/LogViewerQueryDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/LogViewerQueryDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.LogViewerQuery)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal sealed class LogViewerQueryDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.LogViewerQuery;
+
[Column("id")]
[PrimaryKeyColumn]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/LongRunningOperationDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/LongRunningOperationDto.cs
index 8b223b5c06..677eed7eda 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/LongRunningOperationDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/LongRunningOperationDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.LongRunningOperation)]
+[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = false)]
[ExplicitColumns]
internal class LongRunningOperationDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.LongRunningOperation;
+
[Column("id")]
[PrimaryKeyColumn(Name = "PK_umbracoLongRunningOperation", AutoIncrement = false)]
public Guid Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/Member2MemberGroupDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/Member2MemberGroupDto.cs
index 99cb8d2a39..4925f2dd82 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/Member2MemberGroupDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/Member2MemberGroupDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Member2MemberGroup)]
+[TableName(TableName)]
[PrimaryKey("Member", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class Member2MemberGroupDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Member2MemberGroup;
+
[Column("Member")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_cmsMember2MemberGroup", OnColumns = "Member, MemberGroup")]
[ForeignKey(typeof(MemberDto))]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs
index f90824c51e..38e8e36271 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs
@@ -34,7 +34,7 @@ public class NodeDto
[Column(ParentIdColumnName)]
[ForeignKey(typeof(NodeDto))]
- [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_parentId_nodeObjectType", ForColumns = "parentID,nodeObjectType", IncludeColumns = "trashed,nodeUser,level,path,sortOrder,uniqueID,text,createDate")]
+ [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_parentId_nodeObjectType", ForColumns = "parentId,nodeObjectType", IncludeColumns = "trashed,nodeUser,level,path,sortOrder,uniqueID,text,createDate")]
public int ParentId { get; set; }
// NOTE: This index is primarily for the nucache data lookup, see https://github.com/umbraco/Umbraco-CMS/pull/8365#issuecomment-673404177
@@ -48,7 +48,7 @@ public class NodeDto
public string Path { get; set; } = null!;
[Column(SortOrderColumnName)]
- [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_ObjectType_trashed_sorted", ForColumns = "nodeObjectType,trashed,sortOrder,id", IncludeColumns = "uniqueID,parentID,level,path,nodeUser,text,createDate")]
+ [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_ObjectType_trashed_sorted", ForColumns = "nodeObjectType,trashed,sortOrder,id", IncludeColumns = "uniqueID,parentId,level,path,nodeUser,text,createDate")]
public int SortOrder { get; set; }
[Column(TrashedColumnName)]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeDto.cs
index 721ea6c507..943a8c1b21 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.PropertyType)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal class PropertyTypeDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.PropertyType;
+
private string? _alias;
[Column("id")]
@@ -76,7 +78,7 @@ internal class PropertyTypeDto
[Reference(ReferenceType.OneToOne, ColumnName = "DataTypeId")]
public DataTypeDto DataTypeDto { get; set; } = null!;
- [Column("UniqueID")]
+ [Column("UniqueId")]
[NullSetting(NullSetting = NullSettings.NotNull)]
[Constraint(Default = SystemMethods.NewGuid)]
[Index(IndexTypes.UniqueNonClustered, Name = "IX_cmsPropertyTypeUniqueID")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs
index effe2acdf7..3269102562 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs
@@ -3,11 +3,13 @@ using Umbraco.Cms.Core;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.PropertyTypeGroup)]
+[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
internal sealed class PropertyTypeGroupReadOnlyDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.PropertyTypeGroup;
+
[Column("PropertyTypeGroupId")]
public int? Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs
index 14c24499e6..4c4e526693 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs
@@ -3,11 +3,13 @@ using Umbraco.Cms.Core;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.PropertyType)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal sealed class PropertyTypeReadOnlyDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.PropertyType;
+
[Column("PropertyTypeId")]
public int? Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs
index 49ab6c8aa4..e5af860721 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs
@@ -4,7 +4,7 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.RedirectUrl)]
+[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class RedirectUrlDto
@@ -28,7 +28,7 @@ internal sealed class RedirectUrlDto
[Column("contentKey")]
[NullSetting(NullSetting = NullSettings.NotNull)]
- [ForeignKey(typeof(NodeDto), Column = "uniqueID")]
+ [ForeignKey(typeof(NodeDto), Column = "uniqueId")]
public Guid ContentKey { get; set; }
[Column("createDateUtc")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs
index 72c0877c6a..5c15ca53fd 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Relation)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal sealed class RelationDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Relation;
+
[Column("id")]
[PrimaryKeyColumn]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs
index 3856d24ce2..20a43410b6 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.RelationType)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal sealed class RelationTypeDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.RelationType;
+
public const int NodeIdSeed = 10;
[Column("id")]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs
index 28a6fbe6ce..960697cf72 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Server)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
internal sealed class ServerRegistrationDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Server;
+
[Column("id")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs
index 636e152bed..e1462a47fa 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Template)]
+[TableName(TableName)]
[PrimaryKey("pk")]
[ExplicitColumns]
internal sealed class TemplateDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Template;
+
[Column("pk")]
[PrimaryKeyColumn]
public int PrimaryKey { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/User2ClientIdDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/User2ClientIdDto.cs
index dc2399dc6a..9d433fb70a 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/User2ClientIdDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/User2ClientIdDto.cs
@@ -1,14 +1,16 @@
-using NPoco;
+using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.User2ClientId)]
+[TableName(TableName)]
[PrimaryKey("userId", AutoIncrement = false)]
[ExplicitColumns]
public class User2ClientIdDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.User2ClientId;
+
[Column("userId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_umbracoUser2ClientId", OnColumns = "userId, clientId")]
[ForeignKey(typeof(UserDto))]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs
index e25bad1f55..e980230d7f 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.User2NodeNotify)]
+[TableName(TableName)]
[PrimaryKey("userId", AutoIncrement = false)]
[ExplicitColumns]
internal sealed class User2NodeNotifyDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.User2NodeNotify;
+
[Column("userId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_umbracoUser2NodeNotify", OnColumns = "userId, nodeId, action")]
[ForeignKey(typeof(UserDto))]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/User2UserGroupDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/User2UserGroupDto.cs
index 3bc059ff21..fd0da99f39 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/User2UserGroupDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/User2UserGroupDto.cs
@@ -4,10 +4,12 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.User2UserGroup)]
+[TableName(TableName)]
[ExplicitColumns]
public class User2UserGroupDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.User2UserGroup;
+
[Column("userId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_user2userGroup", OnColumns = "userId, userGroupId")]
[ForeignKey(typeof(UserDto))]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs
index 7e2099ae44..4b71e1b714 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs
@@ -4,10 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.UserGroup2App)]
+[TableName(TableName)]
+[PrimaryKey("id", AutoIncrement = false)]
[ExplicitColumns]
public class UserGroup2AppDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.UserGroup2App;
+
[Column("userGroupId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_userGroup2App", OnColumns = "userGroupId, app")]
[ForeignKey(typeof(UserGroupDto))]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2GranularPermissionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2GranularPermissionDto.cs
index 68f2e35bcb..e1cfc16380 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2GranularPermissionDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2GranularPermissionDto.cs
@@ -4,10 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.UserGroup2GranularPermission)]
+[TableName(TableName)]
+[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
public class UserGroup2GranularPermissionDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.UserGroup2GranularPermission;
+
[Column("id")]
[PrimaryKeyColumn(Name = "PK_umbracoUserGroup2GranularPermissionDto", AutoIncrement = true)]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2LanguageDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2LanguageDto.cs
index 1ecf84fafc..36ba42bb4e 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2LanguageDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2LanguageDto.cs
@@ -1,10 +1,10 @@
-using System.Data;
+using System.Data;
using NPoco;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Cms.Core.Constants.DatabaseSchema.Tables.UserGroup2Language)]
+[TableName(TableName)]
[ExplicitColumns]
public class UserGroup2LanguageDto
{
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2PermissionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2PermissionDto.cs
index 9f819a6058..ac095e6e42 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2PermissionDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2PermissionDto.cs
@@ -1,13 +1,16 @@
-using NPoco;
+using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.UserGroup2Permission)]
+[TableName(TableName)]
+[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
public class UserGroup2PermissionDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.UserGroup2Permission;
+
[Column("id")]
[PrimaryKeyColumn(Name = "PK_userGroup2Permission", AutoIncrement = true)]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroupDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroupDto.cs
index 794eceeff5..591b495db6 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroupDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroupDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.UserGroup)]
+[TableName(TableName)]
[PrimaryKey("id")]
[ExplicitColumns]
public class UserGroupDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.UserGroup;
+
public UserGroupDto()
{
UserGroup2AppDtos = new List();
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserStartNodeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserStartNodeDto.cs
index 4d54752e75..51ca08b842 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserStartNodeDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserStartNodeDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.UserStartNode)]
+[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
public class UserStartNodeDto : IEquatable
{
+ public const string TableName = Constants.DatabaseSchema.Tables.UserStartNode;
+
public enum StartNodeTypeValue
{
Content = 1,
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2EventsDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2EventsDto.cs
index 0278d22945..d534cf4c36 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2EventsDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2EventsDto.cs
@@ -1,13 +1,15 @@
-using System.Data;
+using System.Data;
using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Webhook2Events)]
+[TableName(TableName)]
public class Webhook2EventsDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Webhook2Events;
+
[Column("webhookId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_webhookEvent2WebhookDto", OnColumns = "webhookId, event")]
[ForeignKey(typeof(WebhookDto), OnDelete = Rule.Cascade)]
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2HeadersDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2HeadersDto.cs
index 80a7724109..85d0395222 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2HeadersDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/Webhook2HeadersDto.cs
@@ -1,15 +1,17 @@
-using System.Data;
+using System.Data;
using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Webhook2Headers)]
+[TableName(TableName)]
public class Webhook2HeadersDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Webhook2Headers;
+
[Column("webhookId")]
- [PrimaryKeyColumn(AutoIncrement = false, Name = "PK_heaeders2WebhookDto", OnColumns = "webhookId, key")]
+ [PrimaryKeyColumn(AutoIncrement = false, Name = "PK_headers2WebhookDto", OnColumns = "webhookId, key")]
[ForeignKey(typeof(WebhookDto), OnDelete = Rule.Cascade)]
public int WebhookId { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookDto.cs
index 0851d40aad..122a70c288 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookDto.cs
@@ -5,11 +5,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.Webhook)]
-[PrimaryKey("id")]
+[TableName(TableName)]
+[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
internal sealed class WebhookDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.Webhook;
+
[Column("id")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookLogDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookLogDto.cs
index c0f432a417..7c3601601f 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookLogDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookLogDto.cs
@@ -4,11 +4,13 @@ using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.WebhookLog)]
-[PrimaryKey("id")]
+[TableName(TableName)]
+[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
internal sealed class WebhookLogDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.WebhookLog;
+
[Column("id")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookRequestDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookRequestDto.cs
index 80739770a0..240fab3c11 100644
--- a/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookRequestDto.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Dtos/WebhookRequestDto.cs
@@ -1,14 +1,16 @@
-using NPoco;
+using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
-[TableName(Constants.DatabaseSchema.Tables.WebhookRequest)]
-[PrimaryKey("id")]
+[TableName(TableName)]
+[PrimaryKey("id", AutoIncrement = true)]
[ExplicitColumns]
public class WebhookRequestDto
{
+ public const string TableName = Constants.DatabaseSchema.Tables.WebhookRequest;
+
[Column("id")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int Id { get; set; }
diff --git a/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs b/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs
index 71880c95dc..241aa800bf 100644
--- a/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs
+++ b/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs
@@ -92,6 +92,30 @@ namespace Umbraco.Extensions
return sql;
}
+ ///
+ /// Appends a OR IN clause to the Sql statement.
+ ///
+ /// The type of the first Dto.
+ /// The type of the second Dto.
+ /// The Sql statement.
+ /// An expression specifying the first field.
+ /// First values.
+ /// An expression specifying the second field.
+ /// Second values.
+ /// The Sql statement.
+ public static Sql WhereInOr(
+ this Sql sql,
+ Expression> field,
+ Expression> field2,
+ IEnumerable? values,
+ IEnumerable? values2)
+ {
+ var fieldName = sql.SqlContext.SqlSyntax.GetFieldName(field);
+ var fieldName2 = sql.SqlContext.SqlSyntax.GetFieldName(field2);
+ sql.Where($"{fieldName} IN (@values) OR {fieldName2} IN (@values2)", new { values }, new { values2 });
+ return sql;
+ }
+
///
/// Appends a WHERE IN clause to the Sql statement.
///
@@ -141,7 +165,7 @@ namespace Umbraco.Extensions
{
var fieldName = sql.SqlContext.SqlSyntax.GetFieldName(fieldSelector);
var concat = sql.SqlContext.SqlSyntax.GetWildcardConcat(concatDefault);
- var likeSelect = sql.SqlContext.SqlSyntax.GetConcat(valuesSql?.SQL ?? string.Empty, concat);
+ var likeSelect = sql.SqlContext.SqlSyntax.GetConcat($"({valuesSql?.SQL})", concat);
sql.Where($"{fieldName} LIKE {likeSelect}", valuesSql?.Arguments);
return sql;
}
@@ -702,6 +726,64 @@ namespace Umbraco.Extensions
return sql.SqlContext.SqlSyntax.SelectTop(sql, count);
}
+ ///
+ /// Adds a SQL SELECT statement to retrieve the maximum value of the specified field from the table associated
+ /// with the specified DTO type.
+ ///
+ /// The type of the Data Transfer Object (DTO) that represents the table from which the maximum value will be
+ /// selected.
+ /// The SQL query builder to which the SELECT statement will be appended. Cannot be .
+ /// An expression specifying the field for which the maximum value will be calculated. Cannot be .
+ /// A modified SQL query builder that includes the SELECT statement for the maximum value of the specified
+ /// field.
+ public static Sql SelectMax(this Sql sql, Expression> field)
+ {
+ ArgumentNullException.ThrowIfNull(sql);
+ ArgumentNullException.ThrowIfNull(field);
+
+ return sql.Select($"MAX ({sql.SqlContext.SqlSyntax.GetFieldName(field)})");
+ }
+
+ ///
+ /// Adds a SQL SELECT statement to retrieve the maximum value of the specified field from the table associated
+ /// with the specified DTO type.
+ ///
+ /// The type of the Data Transfer Object (DTO) that represents the table from which the maximum value will be
+ /// selected.
+ /// The SQL query builder to which the SELECT statement will be appended. Cannot be .
+ /// An expression specifying the field for which the maximum value will be calculated. Cannot be .
+ /// COALESCE int value.
+ /// A modified SQL query builder that includes the SELECT statement for the maximum value of the specified
+ /// field or the coalesceValue.
+ public static Sql SelectMax(this Sql sql, Expression> field, int coalesceValue)
+ {
+ ArgumentNullException.ThrowIfNull(sql);
+ ArgumentNullException.ThrowIfNull(field);
+
+ return sql.Select($"COALESCE(MAX ({sql.SqlContext.SqlSyntax.GetFieldName(field)}), {coalesceValue})");
+ }
+
+ ///
+ /// Adds a SQL SELECT statement to retrieve the sum of the values of the specified field from the table associated
+ /// with the specified DTO type.
+ ///
+ /// The type of the Data Transfer Object (DTO) that represents the table from which the maximum value will be
+ /// selected.
+ /// The SQL query builder to which the SELECT statement will be appended. Cannot be .
+ /// An expression specifying the field for which the maximum value will be calculated. Cannot be .
+ /// A modified SQL query builder that includes the SELECT statement for the maximum value of the specified
+ /// field.
+ public static Sql SelectSum(this Sql sql, Expression> field)
+ {
+ ArgumentNullException.ThrowIfNull(sql);
+ ArgumentNullException.ThrowIfNull(field);
+
+ return sql.Select($"SUM ({sql.SqlContext.SqlSyntax.GetFieldName(field)})");
+ }
+
///
/// Creates a SELECT COUNT(*) Sql statement.
///
@@ -1246,6 +1328,19 @@ namespace Umbraco.Extensions
return sql;
}
+ ///
+ /// Deletes records from a table based on a predicate.
+ ///
+ /// Table definition.
+ /// SqlConext
+ /// A predicate to transform and append to the Sql statement (WHERE clause).
+ ///
+ public static Sql Delete(this Sql sql, Expression> predicate)
+ {
+ (string s, object[] a) = sql.SqlContext.VisitDto(predicate);
+ return sql.Delete().Where(s, a);
+ }
+
#endregion
#region Update
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs
index b20e9f34d0..bb231db73b 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs
@@ -107,7 +107,7 @@ internal sealed class AuditEntryRepository : EntityRepositoryBase
- protected override string GetBaseWhereClause() => $"{Constants.DatabaseSchema.Tables.AuditEntry}.id = @id";
+ protected override string GetBaseWhereClause() => $"{QuoteTableName(AuditEntryDto.TableName)}.id = @id";
///
protected override IEnumerable GetDeleteClauses() =>
@@ -160,7 +160,7 @@ internal sealed class AuditEntryRepository : EntityRepositoryBase sqlInsert = Sql($"INSERT INTO {Constants.DatabaseSchema.Tables.AuditEntry} ({cols})")
+ Sql sqlInsert = Sql($"INSERT INTO {QuoteTableName(AuditEntryDto.TableName)} ({cols})")
.Append("VALUES (")
.Append(sqlValues)
.Append(")");
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs
index 9ccaa4960c..8d3cb3fb96 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs
@@ -37,9 +37,12 @@ internal sealed class AuditRepository : EntityRepositoryBase, I
{
DateTime oldestPermittedLogEntry = DateTime.UtcNow.Subtract(new TimeSpan(0, maximumAgeOfLogsInMinutes, 0));
- Database.Execute(
- "delete from umbracoLog where datestamp < @oldestPermittedLogEntry and logHeader in ('open','system')",
- new { oldestPermittedLogEntry });
+ var headers = new[] { "open", "system" };
+ Sql sql = SqlContext.Sql()
+ .Delete()
+ .Where(c => c.Datestamp < oldestPermittedLogEntry)
+ .WhereIn(c => c.Header, headers);
+ Database.Execute(sql);
}
///
@@ -70,10 +73,7 @@ internal sealed class AuditRepository : EntityRepositoryBase, I
AuditType[]? auditTypeFilter,
IQuery? customFilter)
{
- if (auditTypeFilter == null)
- {
- auditTypeFilter = Array.Empty();
- }
+ auditTypeFilter ??= [];
Sql sql = GetBaseQuery(false);
@@ -84,7 +84,7 @@ internal sealed class AuditRepository : EntityRepositoryBase, I
{
foreach (Tuple filterClause in customFilter.GetWhereClauses())
{
- sql.Where(filterClause.Item1, filterClause.Item2);
+ sql = sql.Where(filterClause.Item1, filterClause.Item2);
}
}
@@ -92,13 +92,14 @@ internal sealed class AuditRepository : EntityRepositoryBase, I
{
foreach (AuditType type in auditTypeFilter)
{
- sql.Where("(logHeader=@0)", type.ToString());
+ var typeString = type.ToString();
+ sql = sql.Where(c => c.Header == typeString);
}
}
sql = orderDirection == Direction.Ascending
- ? sql.OrderBy("Datestamp")
- : sql.OrderByDescending("Datestamp");
+ ? sql.OrderBy(c => c.Datestamp)
+ : sql.OrderByDescending(c => c.Datestamp);
// get page
Page? page = Database.Page(pageIndex + 1, pageSize, sql);
@@ -118,7 +119,7 @@ internal sealed class AuditRepository : EntityRepositoryBase, I
protected override IAuditItem? PerformGet(int id)
{
Sql sql = GetBaseQuery(false);
- sql.Where(GetBaseWhereClause(), new { id = id });
+ sql.Where(GetBaseWhereClause(), new { id });
LogDto? dto = Database.First(sql);
return dto == null
@@ -158,7 +159,8 @@ internal sealed class AuditRepository : EntityRepositoryBase, I
return sql;
}
- protected override string GetBaseWhereClause() => "umbracoLog.id = @id";
+ protected override string GetBaseWhereClause() =>
+ $"{QuoteTableName(LogDto.TableName)}.{QuoteColumnName("id")} = @id";
protected override IEnumerable GetDeleteClauses() => throw new NotImplementedException();
}
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs
index c623a672d7..e6c9dba4f5 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs
@@ -27,20 +27,42 @@ internal sealed class CacheInstructionRepository : ICacheInstructionRepository
return 0;
}
- Sql? sql = AmbientScope.SqlContext.Sql().Select("COUNT(*)")
+ Sql? sql = AmbientScope.SqlContext.Sql().SelectCount()
.From();
- return AmbientScope?.Database.ExecuteScalar(sql) ?? 0;
+ return AmbientScope.Database.ExecuteScalar(sql);
}
///
- public int CountPendingInstructions(int lastId) =>
- AmbientScope?.Database.ExecuteScalar(
- "SELECT SUM(instructionCount) FROM umbracoCacheInstruction WHERE id > @lastId", new { lastId }) ?? 0;
+ public int CountPendingInstructions(int lastId)
+ {
+ if (AmbientScope is null)
+ {
+ return 0;
+ }
+
+ Sql? sql = AmbientScope.SqlContext.Sql()
+ .SelectSum(c => c.InstructionCount)
+ .From()
+ .Where(dto => dto.Id > lastId);
+
+ return AmbientScope.Database.ExecuteScalar(sql);
+ }
///
- public int GetMaxId() =>
- AmbientScope?.Database.ExecuteScalar("SELECT MAX(id) FROM umbracoCacheInstruction") ?? 0;
+ public int GetMaxId()
+ {
+ if (AmbientScope is null)
+ {
+ return 0;
+ }
+
+ Sql sql = AmbientScope.SqlContext.Sql()
+ .SelectMax(c => c.Id)
+ .From();
+
+ return AmbientScope.Database.ExecuteScalar(sql);
+ }
///
public bool Exists(int id) => AmbientScope?.Database.Exists(id) ?? false;
@@ -71,12 +93,25 @@ internal sealed class CacheInstructionRepository : ICacheInstructionRepository
///
public void DeleteInstructionsOlderThan(DateTime pruneDate)
{
+ if (AmbientScope is null)
+ {
+ return;
+ }
+
// Using 2 queries is faster than convoluted joins.
- var maxId = AmbientScope?.Database.ExecuteScalar("SELECT MAX(id) FROM umbracoCacheInstruction;");
- Sql deleteSql =
- new Sql().Append(
- @"DELETE FROM umbracoCacheInstruction WHERE utcStamp < @pruneDate AND id < @maxId",
- new { pruneDate, maxId });
- AmbientScope?.Database.Execute(deleteSql);
+ Sql sql = AmbientScope.SqlContext.Sql()
+ .SelectMax(c => c.Id)
+ .From();
+ var maxId = AmbientScope.Database.ExecuteScalar(sql);
+ if (maxId == 0)
+ {
+ return; // No instructions to delete.
+ }
+
+ Sql? deleteSql = AmbientScope.SqlContext.Sql()
+ .Delete()
+ .Where(dto => dto.UtcStamp < pruneDate && dto.Id < maxId);
+
+ AmbientScope.Database.Execute(deleteSql);
}
}
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentNavigationRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentNavigationRepository.cs
index d184be555b..ce4592d129 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentNavigationRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentNavigationRepository.cs
@@ -2,6 +2,7 @@ using NPoco;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
+using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax;
using Umbraco.Cms.Infrastructure.Scoping;
using Umbraco.Extensions;
@@ -31,14 +32,16 @@ public class ContentNavigationRepository : INavigationRepository
return Enumerable.Empty();
}
+ ISqlSyntaxProvider syntax = AmbientScope.SqlContext.SqlSyntax;
+
Sql sql = AmbientScope.SqlContext.Sql()
.Select(
- $"n.{NodeDto.IdColumnName} as {NodeDto.IdColumnName}",
- $"n.{NodeDto.KeyColumnName} as {NodeDto.KeyColumnName}",
- $"ctn.{NodeDto.KeyColumnName} as {NavigationDto.ContentTypeKeyColumnName}",
- $"n.{NodeDto.ParentIdColumnName} as {NodeDto.ParentIdColumnName}",
- $"n.{NodeDto.SortOrderColumnName} as {NodeDto.SortOrderColumnName}",
- $"n.{NodeDto.TrashedColumnName} as {NodeDto.TrashedColumnName}")
+ $"n.{syntax.GetQuotedColumnName(NodeDto.IdColumnName)} as {syntax.GetQuotedColumnName(NodeDto.IdColumnName)}",
+ $"n.{syntax.GetQuotedColumnName(NodeDto.KeyColumnName)} as {syntax.GetQuotedColumnName(NodeDto.KeyColumnName)}",
+ $"ctn.{syntax.GetQuotedColumnName(NodeDto.KeyColumnName)} as {syntax.GetQuotedColumnName(NavigationDto.ContentTypeKeyColumnName)}",
+ $"n.{syntax.GetQuotedColumnName(NodeDto.ParentIdColumnName)} as {syntax.GetQuotedColumnName(NodeDto.ParentIdColumnName)}",
+ $"n.{syntax.GetQuotedColumnName(NodeDto.SortOrderColumnName)} as {syntax.GetQuotedColumnName(NodeDto.SortOrderColumnName)}",
+ $"n.{syntax.GetQuotedColumnName(NodeDto.TrashedColumnName)} as {syntax.GetQuotedColumnName(NodeDto.TrashedColumnName)}")
.From("n")
.InnerJoin("c").On((n, c) => n.NodeId == c.NodeId, "n", "c")
.InnerJoin("ctn").On((c, ctn) => c.ContentTypeId == ctn.NodeId, "c", "ctn")
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs
index 457271c1c9..32398b35f5 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs
@@ -529,12 +529,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
// needs to be an outer join since there's no guarantee that any of the nodes have values for this property
Sql innerSql = Sql().Select($@"CASE
- WHEN intValue IS NOT NULL THEN {sortedInt}
- WHEN decimalValue IS NOT NULL THEN {sortedDecimal}
- WHEN dateValue IS NOT NULL THEN {sortedDate}
+ WHEN {QuoteColumnName("intValue")} IS NOT NULL THEN {sortedInt}
+ WHEN {QuoteColumnName("decimalValue")} IS NOT NULL THEN {sortedDecimal}
+ WHEN {QuoteColumnName("dateValue")} IS NOT NULL THEN {sortedDate}
ELSE {sortedString}
- END AS customPropVal,
- cver.nodeId AS customPropNodeId")
+ END AS {SqlSyntax.GetQuotedName("customPropVal")},
+ cver.{QuoteColumnName("nodeId")} AS {SqlSyntax.GetQuotedName("customPropNodeId")}")
.From("cver")
.InnerJoin("opdata")
.On((version, pdata) => version.Id == pdata.VersionId, "cver", "opdata")
@@ -549,14 +549,14 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
var innerSqlString = ParameterHelper.ProcessParams(innerSql.SQL, innerSql.Arguments, argsList);
// create the outer join complete sql fragment
- var outerJoinTempTable = $@"LEFT OUTER JOIN ({innerSqlString}) AS customPropData
- ON customPropData.customPropNodeId = {Constants.DatabaseSchema.Tables.Node}.id "; // trailing space is important!
+ var outerJoinTempTable = $@"LEFT OUTER JOIN ({innerSqlString}) AS {SqlSyntax.GetQuotedName("customPropData")}
+ ON {SqlSyntax.GetQuotedName("customPropData")}.{QuoteColumnName("customPropNodeId")} = {QuoteTableName(NodeDto.TableName)}.id "; // trailing space is important!
// insert this just above the first WHERE
var newSql = InsertBefore(sql.SQL, "WHERE", outerJoinTempTable);
// see notes in ApplyOrdering: the field MUST be selected + aliased
- newSql = InsertBefore(newSql, "FROM", ", customPropData.customPropVal AS ordering "); // trailing space is important!
+ newSql = InsertBefore(newSql, "FROM", $", {SqlSyntax.GetQuotedName("customPropData")}.{QuoteColumnName("customPropVal")} AS ordering "); // trailing space is important!
// create the new sql
sql = Sql(newSql, argsList.ToArray());
@@ -906,7 +906,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
protected string GetQuotedFieldName(string tableName, string fieldName)
{
- return SqlContext.SqlSyntax.GetQuotedTableName(tableName) + "." + SqlContext.SqlSyntax.GetQuotedColumnName(fieldName);
+ return QuoteTableName(tableName) + "." + QuoteColumnName(fieldName);
}
#region UnitOfWork Notification
@@ -1015,7 +1015,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
protected virtual bool SortorderExists(int parentId, int sortOrder)
{
SqlTemplate? template = SqlContext.Templates.Get(Constants.SqlTemplates.VersionableRepository.SortOrderExists, tsql => tsql
- .Select("sortOrder")
+ .Select(c => c.SortOrder)
.From()
.Where(x => x.NodeObjectType == SqlTemplate.Arg("nodeObjectType") &&
x.ParentId == SqlTemplate.Arg("parentId") &&
@@ -1030,7 +1030,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
protected virtual int GetNewChildSortOrder(int parentId, int first)
{
SqlTemplate? template = SqlContext.Templates.Get(Constants.SqlTemplates.VersionableRepository.GetSortOrder, tsql => tsql
- .Select("MAX(sortOrder)")
+ .SelectMax(c => c.SortOrder)
.From()
.Where(x => x.NodeObjectType == SqlTemplate.Arg("nodeObjectType") && x.ParentId == SqlTemplate.Arg("parentId")));
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs
index c6c00eb637..c01c0936d8 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs
@@ -1,3 +1,4 @@
+using System.Xml.Linq;
using Microsoft.Extensions.Logging;
using NPoco;
using Umbraco.Cms.Core;
@@ -47,8 +48,14 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase
///
- public IEnumerable GetAllPropertyTypeAliases() =>
- Database.Fetch("SELECT DISTINCT Alias FROM cmsPropertyType ORDER BY Alias");
+ public IEnumerable GetAllPropertyTypeAliases()
+ {
+ Sql sql = Sql()
+ .SelectDistinct(c => c.Alias)
+ .From()
+ .OrderBy(c => c.Alias);
+ return Database.Fetch(sql);
+ }
///
/// Gets all content type aliases
@@ -61,7 +68,7 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase GetAllContentTypeAliases(params Guid[] objectTypes)
{
Sql sql = Sql()
- .Select("cmsContentType.alias")
+ .Select(c => c.Alias)
.From()
.InnerJoin()
.On(dto => dto.NodeId, dto => dto.NodeId);
@@ -177,15 +184,15 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase $"{Constants.DatabaseSchema.Tables.Node}.id = @id";
+ protected override string GetBaseWhereClause() => $"{QuoteTableName(NodeDto.TableName)}.id = @id";
protected override IEnumerable GetDeleteClauses()
{
var l = (List)base.GetDeleteClauses(); // we know it's a list
- l.Add("DELETE FROM umbracoContentVersionCleanupPolicy WHERE contentTypeId = @id");
- l.Add("DELETE FROM cmsDocumentType WHERE contentTypeNodeId = @id");
- l.Add("DELETE FROM cmsContentType WHERE nodeId = @id");
- l.Add("DELETE FROM umbracoNode WHERE id = @id");
+ l.Add($"DELETE FROM {QuoteTableName(ContentVersionCleanupPolicyDto.TableName)} WHERE {QuoteColumnName("contentTypeId")} = @id");
+ l.Add($"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.DocumentType)} WHERE {QuoteColumnName("contentTypeNodeId")} = @id");
+ l.Add($"DELETE FROM {QuoteTableName(ContentTypeDto.TableName)} WHERE {QuoteColumnName("nodeId")} = @id");
+ l.Add($"DELETE FROM {QuoteTableName(NodeDto.TableName)} WHERE id = @id");
return l;
}
@@ -211,7 +218,7 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase sql = Sql()
- .Select("DISTINCT " + Constants.DatabaseSchema.Tables.PropertyData + ".propertytypeid")
+ .SelectDistinct(c => c.PropertyTypeId)
.From()
.InnerJoin()
.On(dto => dto.PropertyTypeId, dto => dto.Id)
@@ -220,7 +227,7 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase(dto => dto.NodeId == entity.Id);
// Delete all PropertyData where propertytypeid EXISTS in the subquery above
- Database.Execute(SqlSyntax.GetDeleteSubquery(Constants.DatabaseSchema.Tables.PropertyData, "propertytypeid", sql));
+ Database.Execute(SqlSyntax.GetDeleteSubquery(PropertyDataDto.TableName, "propertyTypeId", sql));
// delete all granular permissions for this content type
Database.Delete(Sql().Where(dto => dto.UniqueId == entity.Key));
@@ -252,7 +259,10 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase("WHERE contentTypeNodeId = @Id", new { entity.Id });
+ Sql sql = Sql()
+ .Delete()
+ .Where(x => x.ContentTypeNodeId == entity.Id);
+ Database.Execute(sql);
// we could do it all in foreach if we assume that the default template is an allowed template??
var defaultTemplateId = entity.DefaultTemplateId;
@@ -260,7 +270,9 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase("WHERE id = @ParentId", new { entity.ParentId });
+ Sql sql = Sql()
+ .SelectAll()
+ .From()
+ .Where(x => x.NodeId == entity.ParentId);
+ NodeDto parent = Database.First(sql);
entity.Path = string.Concat(parent.Path, ",", entity.Id);
entity.Level = parent.Level + 1;
- var maxSortOrder =
- Database.ExecuteScalar(
- "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
- new { entity.ParentId, NodeObjectType = NodeObjectTypeId });
+ sql = Sql()
+ .SelectMax(c => c.SortOrder, 0)
+ .From()
+ .Where(x => x.ParentId == entity.ParentId && x.NodeObjectType == NodeObjectTypeId);
+ var maxSortOrder = Database.ExecuteScalar(sql);
entity.SortOrder = maxSortOrder + 1;
}
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs
index befaa6bc3a..74f6ff4c52 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs
@@ -986,7 +986,7 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
.From()
.InnerJoin().On(x => x.NodeId, x => x.NodeId)
.Where(x => x.ContentTypeId == contentType.Id);
- Sql? sqlInsertContentVersion = Sql($"INSERT INTO {SqlSyntax.GetQuotedTableName(ContentVersionCultureVariationDto.TableName)} ({cols})")
+ Sql? sqlInsertContentVersion = Sql($"INSERT INTO {QuoteTableName(ContentVersionCultureVariationDto.TableName)} ({cols})")
.Append(sqlSelect2);
Database.Execute(sqlInsertContentVersion);
@@ -996,12 +996,12 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
x => x.Name, x => x.Available, x => x.LanguageId);
Sql sqlSelectDocument = Sql().Select(x => x.NodeId, x => x.Edited, x => x.Published)
.AndSelect(x => x.Text)
- .Append($", 1, {defaultLanguageId}") // make Available + default language ID
+ .Append($", {SqlSyntax.ConvertIntegerToBoolean(1)}, {defaultLanguageId}") // make Available + default language ID
.From()
.InnerJoin().On(x => x.NodeId, x => x.NodeId)
.InnerJoin().On(x => x.NodeId, x => x.NodeId)
.Where(x => x.ContentTypeId == contentType.Id);
- Sql sqlInsertDocumentCulture = Sql($"INSERT INTO {SqlSyntax.GetQuotedTableName(DocumentCultureVariationDto.TableName)} ({cols})").Append(sqlSelectDocument);
+ Sql sqlInsertDocumentCulture = Sql($"INSERT INTO {QuoteTableName(DocumentCultureVariationDto.TableName)} ({cols})").Append(sqlSelectDocument);
Database.Execute(sqlInsertDocumentCulture);
}
@@ -1087,7 +1087,7 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
.Where(x => x.LanguageId.SqlNullableEquals(sourceLanguageId, -1));
var cols = Sql().ColumnsForInsert(x => x.Text, x => x.Group, x => x.LanguageId);
- Sql? sqlInsertTags = Sql($"INSERT INTO {SqlSyntax.GetQuotedTableName(TagDto.TableName)} ({cols})").Append(sqlSelectTagsToInsert1);
+ Sql? sqlInsertTags = Sql($"INSERT INTO {QuoteTableName(TagDto.TableName)} ({cols})").Append(sqlSelectTagsToInsert1);
Database.Execute(sqlInsertTags);
@@ -1122,7 +1122,7 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
var relationColumnsToInsert =
Sql().ColumnsForInsert(x => x.NodeId, x => x.PropertyTypeId, x => x.TagId);
Sql? sqlInsertRelations =
- Sql($"INSERT INTO {SqlSyntax.GetQuotedTableName(TagRelationshipDto.TableName)} ({relationColumnsToInsert})")
+ Sql($"INSERT INTO {QuoteTableName(TagRelationshipDto.TableName)} ({relationColumnsToInsert})")
.Append(sqlSelectRelationsToInsert);
Database.Execute(sqlInsertRelations);
@@ -1241,7 +1241,7 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
.WhereIn(x => x.ContentTypeId, contentTypeIds);
}
- Sql? sqlInsert = Sql($"INSERT INTO {SqlSyntax.GetQuotedTableName(PropertyDataDto.TableName)} ({cols})").Append(sqlSelectData);
+ Sql? sqlInsert = Sql($"INSERT INTO {QuoteTableName(PropertyDataDto.TableName)} ({cols})").Append(sqlSelectData);
Database.Execute(sqlInsert);
@@ -1582,6 +1582,7 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
.WhereLike(c => c.Alias, $"{alias}{SqlSyntax.GetWildcardPlaceholder()}");
List aliases = Database.Fetch(sql);
+
var i = 1;
string test;
while (aliases.Contains(test = alias + i))
@@ -1617,7 +1618,7 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
public bool HasContentNodes(int id)
{
var sql = new Sql(
- $"SELECT CASE WHEN EXISTS (SELECT * FROM {SqlSyntax.GetQuotedTableName(ContentDto.TableName)} WHERE {SqlSyntax.GetQuotedColumnName("contentTypeId")} = @id) THEN 1 ELSE 0 END",
+ $"SELECT CASE WHEN EXISTS (SELECT * FROM {QuoteTableName(ContentDto.TableName)} WHERE {QuoteColumnName("contentTypeId")} = @id) THEN 1 ELSE 0 END",
new { id });
return Database.ExecuteScalar(sql) == 1;
}
@@ -1629,18 +1630,18 @@ internal abstract class ContentTypeRepositoryBase : EntityRepositoryBas
// is included here just to be 100% sure since it has a FK on cmsPropertyType.
var list = new List
{
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.User2NodeNotify)} WHERE {SqlSyntax.GetQuotedColumnName("nodeId")} = @id",
- $@"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.UserGroup2GranularPermission)} WHERE {SqlSyntax.GetQuotedColumnName("uniqueId")} IN
- (SELECT {SqlSyntax.GetQuotedColumnName("uniqueId")} FROM {SqlSyntax.GetQuotedTableName(NodeDto.TableName)} WHERE id = @id)",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.TagRelationship)} WHERE {SqlSyntax.GetQuotedColumnName("nodeId")} = @id",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.ContentChildType)} WHERE {SqlSyntax.GetQuotedColumnName("Id")} = @id",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.ContentChildType)} WHERE {SqlSyntax.GetQuotedColumnName("AllowedId")} = @id",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.ContentTypeTree)} WHERE {SqlSyntax.GetQuotedColumnName("parentContentTypeId")} = @id",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.ContentTypeTree)} WHERE {SqlSyntax.GetQuotedColumnName("childContentTypeId")} = @id",
- $@"DELETE FROM {SqlSyntax.GetQuotedTableName(PropertyDataDto.TableName)} WHERE {SqlSyntax.GetQuotedColumnName("propertyTypeId")} IN
- (SELECT id FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.PropertyType)} WHERE {SqlSyntax.GetQuotedColumnName("contentTypeId")} = @id)",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.PropertyType)} WHERE {SqlSyntax.GetQuotedColumnName("contentTypeId")} = @id",
- $"DELETE FROM {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.PropertyTypeGroup)} WHERE {SqlSyntax.GetQuotedColumnName("contenttypeNodeId")} = @id",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.User2NodeNotify)} WHERE {QuoteColumnName("nodeId")} = @id",
+ $@"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.UserGroup2GranularPermission)} WHERE {QuoteColumnName("uniqueId")} IN
+ (SELECT {QuoteColumnName("uniqueId")} FROM {QuoteTableName(NodeDto.TableName)} WHERE id = @id)",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.TagRelationship)} WHERE {QuoteColumnName("nodeId")} = @id",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.ContentChildType)} WHERE {QuoteColumnName("Id")} = @id",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.ContentChildType)} WHERE {QuoteColumnName("AllowedId")} = @id",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.ContentTypeTree)} WHERE {QuoteColumnName("parentContentTypeId")} = @id",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.ContentTypeTree)} WHERE {QuoteColumnName("childContentTypeId")} = @id",
+ $@"DELETE FROM {QuoteTableName(PropertyDataDto.TableName)} WHERE {QuoteColumnName("propertyTypeId")} IN
+ (SELECT id FROM {QuoteTableName(Constants.DatabaseSchema.Tables.PropertyType)} WHERE {QuoteColumnName("contentTypeId")} = @id)",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.PropertyType)} WHERE {QuoteColumnName("contentTypeId")} = @id",
+ $"DELETE FROM {QuoteTableName(Constants.DatabaseSchema.Tables.PropertyTypeGroup)} WHERE {QuoteColumnName("contenttypeNodeId")} = @id",
};
return list;
}
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs
index 3e55ee442f..b97a200cbb 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs
@@ -49,7 +49,7 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
protected Guid NodeObjectTypeId => Constants.ObjectTypes.DataType;
- public IDataType? Get(Guid key) => GetMany().FirstOrDefault(x=>x.Key == key);
+ public IDataType? Get(Guid key) => GetMany().FirstOrDefault(x => x.Key == key);
public IEnumerable> Move(IDataType toMove, EntityContainer? container)
{
@@ -257,7 +257,7 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
if (ids?.Any() ?? false)
{
- dataTypeSql.Where("umbracoNode.id in (@ids)", new { ids });
+ dataTypeSql.WhereIn(w => w.NodeId, ids);
}
else
{
@@ -309,7 +309,7 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
return sql;
}
- protected override string GetBaseWhereClause() => "umbracoNode.id = @id";
+ protected override string GetBaseWhereClause() => $"{QuoteTableName("umbracoNode")}.id = @id";
protected override IEnumerable GetDeleteClauses() => Array.Empty();
@@ -340,12 +340,17 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
DataTypeDto dto = DataTypeFactory.BuildDto(entity, _serializer);
// Logic for setting Path, Level and SortOrder
- NodeDto? parent = Database.First("WHERE id = @ParentId", new { entity.ParentId });
+ Sql sql = Sql()
+ .SelectAll()
+ .From()
+ .Where(x => x.NodeId == entity.ParentId);
+ NodeDto parent = Database.First(sql);
var level = parent.Level + 1;
- var sortOrder =
- Database.ExecuteScalar(
- "SELECT COUNT(*) FROM umbracoNode WHERE parentID = @ParentId AND nodeObjectType = @NodeObjectType",
- new { entity.ParentId, NodeObjectType = NodeObjectTypeId });
+ sql = Sql()
+ .SelectCount()
+ .From()
+ .Where(x => x.ParentId == entity.ParentId && x.NodeObjectType == NodeObjectTypeId);
+ var sortOrder = Database.ExecuteScalar(sql);
// Create the (base) node data - umbracoNode
NodeDto nodeDto = dto.NodeDto;
@@ -355,7 +360,7 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
var o = Database.IsNew(nodeDto) ? Convert.ToInt32(Database.Insert(nodeDto)) : Database.Update(nodeDto);
// Update with new correct path
- nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId);
+ nodeDto.Path = string.Concat(nodeDto.Path, ",", nodeDto.NodeId);
Database.Update(nodeDto);
// Update entity with correct values
@@ -392,13 +397,19 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
// Look up parent to get and set the correct Path if ParentId has changed
if (entity.IsPropertyDirty("ParentId"))
{
- NodeDto? parent = Database.First("WHERE id = @ParentId", new { entity.ParentId });
- entity.Path = string.Concat(parent.Path, ",", entity.Id);
- entity.Level = parent.Level + 1;
- var maxSortOrder =
- Database.ExecuteScalar(
- "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
- new { entity.ParentId, NodeObjectType = NodeObjectTypeId });
+ Sql sql = Sql()
+ .SelectAll()
+ .From()
+ .Where(x => x.NodeId == entity.ParentId);
+ NodeDto? parent = Database.FirstOrDefault(sql);
+ entity.Path = string.Concat(parent?.Path ?? "-1", ",", entity.Id);
+ entity.Level = (parent?.Level ?? 0) + 1;
+
+ sql = Sql()
+ .SelectMax(c => c.SortOrder, 0)
+ .From()
+ .Where(x => x.ParentId == entity.ParentId && x.NodeObjectType == NodeObjectTypeId);
+ var maxSortOrder = Database.ExecuteScalar(sql);
entity.SortOrder = maxSortOrder + 1;
}
@@ -414,31 +425,44 @@ internal sealed class DataTypeRepository : EntityRepositoryBase,
protected override void PersistDeletedItem(IDataType entity)
{
+ Sql sql;
+
// Remove Notifications
- Database.Delete("WHERE nodeId = @Id", new { entity.Id });
+ sql = Sql().Delete(x => x.NodeId == entity.Id);
+ Database.Execute(sql);
// Remove Permissions
- Database.Delete("WHERE uniqueId = @Key", new { entity.Key });
+ sql = Sql().Delete(x => x.UniqueId == entity.Key);
+ Database.Execute(sql);
// Remove associated tags
- Database.Delete("WHERE nodeId = @Id", new { entity.Id });
+ sql = Sql().Delete(x => x.NodeId == entity.Id);
+ Database.Execute(sql);
// PropertyTypes containing the DataType being deleted
- List? propertyTypeDtos =
- Database.Fetch("WHERE dataTypeId = @Id", new { entity.Id });
+ sql = Sql()
+ .SelectAll()
+ .From()
+ .Where(x => x.DataTypeId == entity.Id);
+ List? propertyTypeDtos = Database.Fetch(sql);
// Go through the PropertyTypes and delete referenced PropertyData before deleting the PropertyType
foreach (PropertyTypeDto? dto in propertyTypeDtos)
{
- Database.Delete("WHERE propertytypeid = @Id", new { dto.Id });
- Database.Delete("WHERE id = @Id", new { dto.Id });
+ sql = Sql().Delete(x => x.PropertyTypeId == dto.Id);
+ Database.Execute(sql);
+
+ sql = Sql().Delete(x => x.Id == dto.Id);
+ Database.Execute(sql);
}
// Delete Content specific data
- Database.Delete("WHERE nodeId = @Id", new { entity.Id });
+ sql = Sql().Delete(x => x.NodeId == entity.Id);
+ Database.Execute(sql);
// Delete (base) node data
- Database.Delete("WHERE uniqueID = @Id", new { Id = entity.Key });
+ sql = Sql().Delete(x => x.UniqueId == entity.Key);
+ Database.Execute(sql);
entity.DeleteDate = DateTime.UtcNow;
}
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs
index 473f449557..47080a231d 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs
@@ -22,6 +22,8 @@ internal sealed class DictionaryRepository : EntityRepositoryBase $"{QuoteTableName(DictionaryDto.TableName)}.{QuoteColumnName(columnName)}";
+
public DictionaryRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger,
ILoggerFactory loggerFactory, ILanguageRepository languageRepository)
: base(scopeAccessor, cache, logger)
@@ -60,7 +62,7 @@ internal sealed class DictionaryRepository : EntityRepositoryBase GetDictionaryItemKeyMap()
{
- var columns = new[] { "key", "id" }.Select(x => (object)SqlSyntax.GetQuotedColumnName(x)).ToArray();
+ var columns = new[] { "key", "id" }.Select(x => (object)QuotedColumn(x)).ToArray();
Sql sql = Sql().Select(columns).From