Changes new relation repository Sql statements to use sql templates

This commit is contained in:
Shannon
2020-12-16 13:04:11 +11:00
parent 6f1120b610
commit 9269271649
3 changed files with 28 additions and 14 deletions

View File

@@ -19,6 +19,11 @@
public const string DeleteByParentAll = "Umbraco.Core.RelationRepository.DeleteByParent";
public const string DeleteByParentIn = "Umbraco.Core.RelationRepository.DeleteByParentIn";
}
public static class DataTypeRepository
{
public const string EnsureUniqueNodeName = "Umbraco.Core.DataTypeDefinitionRepository.EnsureUniqueNodeName";
}
}
}
}

View File

@@ -303,7 +303,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
private string EnsureUniqueNodeName(string nodeName, int id = 0)
{
var template = SqlContext.Templates.Get("Umbraco.Core.DataTypeDefinitionRepository.EnsureUniqueNodeName", tsql => tsql
var template = SqlContext.Templates.Get(Constants.SqlTemplates.DataTypeRepository.EnsureUniqueNodeName, tsql => tsql
.Select<NodeDto>(x => Alias(x.NodeId, "id"), x => Alias(x.Text, "name"))
.From<NodeDto>()
.Where<NodeDto>(x => x.NodeObjectType == SqlTemplate.Arg<Guid>("nodeObjectType")));

View File

@@ -283,15 +283,15 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
return result;
}
public void DeleteByParent(int parentId, params string[] relationTypeAliases)
{
if (Database.DatabaseType.IsSqlCe())
{
var subQuery = Sql().Select<RelationDto>(x => x.Id)
.From<RelationDto>()
.InnerJoin<RelationTypeDto>().On<RelationDto, RelationTypeDto>(x => x.RelationType, x => x.Id)
.Where<RelationDto>(x => x.ParentId == parentId);
.From<RelationDto>()
.InnerJoin<RelationTypeDto>().On<RelationDto, RelationTypeDto>(x => x.RelationType, x => x.Id)
.Where<RelationDto>(x => x.ParentId == parentId);
if (relationTypeAliases.Length > 0)
{
@@ -305,20 +305,29 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
{
if (relationTypeAliases.Length > 0)
{
var sql = Sql().Delete<RelationDto>()
.From<RelationDto>()
.InnerJoin<RelationTypeDto>().On<RelationDto, RelationTypeDto>(x => x.RelationType, x => x.Id)
.Where<RelationDto>(x => x.ParentId == parentId)
.WhereIn<RelationTypeDto>(x => x.Alias, relationTypeAliases);
var template = SqlContext.Templates.Get(
Constants.SqlTemplates.RelationRepository.DeleteByParentIn,
tsql => Sql().Delete<RelationDto>()
.From<RelationDto>()
.InnerJoin<RelationTypeDto>().On<RelationDto, RelationTypeDto>(x => x.RelationType, x => x.Id)
.Where<RelationDto>(x => x.ParentId == SqlTemplate.Arg<int>("parentId"))
.WhereIn<RelationTypeDto>(x => x.Alias, SqlTemplate.ArgIn<int>("relationTypeAliases")));
var sql = template.Sql(parentId, relationTypeAliases);
Database.Execute(sql);
}
else
{
var template = SqlContext.Templates.Get(
Constants.SqlTemplates.RelationRepository.DeleteByParentAll,
tsql => Sql().Delete<RelationDto>()
.From<RelationDto>()
.InnerJoin<RelationTypeDto>().On<RelationDto, RelationTypeDto>(x => x.RelationType, x => x.Id)
.Where<RelationDto>(x => x.ParentId == SqlTemplate.Arg<int>("parentId")));
var sql = template.Sql(parentId);
var sql = Sql().Delete<RelationDto>()
.From<RelationDto>()
.InnerJoin<RelationTypeDto>().On<RelationDto, RelationTypeDto>(x => x.RelationType, x => x.Id)
.Where<RelationDto>(x => x.ParentId == parentId);
Database.Execute(sql);
}
}