Fixes bulk insert records, adjusts parsing of object types
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
public static UmbracoObjectTypes GetUmbracoObjectType(string name)
|
||||
{
|
||||
return (UmbracoObjectTypes) Enum.Parse(typeof (UmbracoObjectTypes), name, false);
|
||||
return (UmbracoObjectTypes) Enum.Parse(typeof (UmbracoObjectTypes), name, true);
|
||||
}
|
||||
|
||||
#region Guid object type utilities
|
||||
|
||||
@@ -14,7 +14,21 @@ namespace Umbraco.Core.Persistence
|
||||
/// </summary>
|
||||
public static partial class NPocoDatabaseExtensions
|
||||
{
|
||||
// TODO: review NPoco native InsertBulk to replace the code below
|
||||
/// <summary>
|
||||
/// Configures NPoco's SqlBulkCopyHelper to use the correct SqlConnection and SqlTransaction instances from the underlying RetryDbConnection and ProfiledDbTransaction
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is required to use NPoco's own <see cref="Database.InsertBulk{T}(IEnumerable{T})" /> method because we use wrapped DbConnection and DbTransaction instances.
|
||||
/// NPoco's InsertBulk method only caters for efficient bulk inserting records for Sql Server, it does not cater for bulk inserting of records for
|
||||
/// any other database type and in which case will just insert records one at a time.
|
||||
/// NPoco's InsertBulk method also deals with updating the passed in entity's PK/ID once it's inserted whereas our own BulkInsertRecords methods
|
||||
/// do not handle this scenario.
|
||||
/// </remarks>
|
||||
public static void ConfigureNPocoBulkExtensions()
|
||||
{
|
||||
SqlBulkCopyHelper.SqlConnectionResolver = dbConn => GetTypedConnection<SqlConnection>(dbConn);
|
||||
SqlBulkCopyHelper.SqlTransactionResolver = dbTran => GetTypedTransaction<SqlTransaction>(dbTran);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulk-inserts records within a transaction.
|
||||
@@ -235,7 +249,7 @@ namespace Umbraco.Core.Persistence
|
||||
//we need to add column mappings here because otherwise columns will be matched by their order and if the order of them are different in the DB compared
|
||||
//to the order in which they are declared in the model then this will not work, so instead we will add column mappings by name so that this explicitly uses
|
||||
//the names instead of their ordering.
|
||||
foreach(var col in bulkReader.ColumnMappings)
|
||||
foreach (var col in bulkReader.ColumnMappings)
|
||||
{
|
||||
copy.ColumnMappings.Add(col.DestinationColumn, col.DestinationColumn);
|
||||
}
|
||||
|
||||
@@ -236,6 +236,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
},
|
||||
RelationFactory.BuildDto); // value = DTO
|
||||
|
||||
// Use NPoco's own InsertBulk command which will automatically re-populate the new Ids on the entities, our own
|
||||
// BulkInsertRecords does not cater for this.
|
||||
Database.InsertBulk(entitiesAndDtos.Values);
|
||||
|
||||
// All dtos now have IDs assigned
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace Umbraco.Core.Persistence
|
||||
_commandRetryPolicy = commandRetryPolicy;
|
||||
|
||||
EnableSqlTrace = EnableSqlTraceDefault;
|
||||
|
||||
NPocoDatabaseExtensions.ConfigureNPocoBulkExtensions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,6 +59,8 @@ namespace Umbraco.Core.Persistence
|
||||
_logger = logger;
|
||||
|
||||
EnableSqlTrace = EnableSqlTraceDefault;
|
||||
|
||||
NPocoDatabaseExtensions.ConfigureNPocoBulkExtensions();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -952,34 +952,10 @@ namespace Umbraco.Web.Editors
|
||||
throw new NotSupportedException("Both pageNumber and pageSize must be greater than zero");
|
||||
}
|
||||
|
||||
UmbracoObjectTypes entity;
|
||||
string udiEntity;
|
||||
|
||||
switch (entityType.ToUpperInvariant())
|
||||
{
|
||||
case "DOCUMENT":
|
||||
entity = UmbracoObjectTypes.Document;
|
||||
udiEntity = Constants.UdiEntityType.Document;
|
||||
break;
|
||||
|
||||
case "MEDIA":
|
||||
entity = UmbracoObjectTypes.Media;
|
||||
udiEntity = Constants.UdiEntityType.Media;
|
||||
break;
|
||||
|
||||
case "MEMBER":
|
||||
entity = UmbracoObjectTypes.Member;
|
||||
udiEntity = Constants.UdiEntityType.Member;
|
||||
break;
|
||||
|
||||
default:
|
||||
entity = UmbracoObjectTypes.Document;
|
||||
udiEntity = Constants.UdiEntityType.Document;
|
||||
break;
|
||||
}
|
||||
|
||||
var relations = Services.RelationService.GetPagedParentEntitiesByChildId(id, pageNumber - 1, pageSize, out long totalRecords, entity);
|
||||
var objectType = ObjectTypes.GetUmbracoObjectType(entityType);
|
||||
var udiType = ObjectTypes.GetUdiType(objectType);
|
||||
|
||||
var relations = Services.RelationService.GetPagedParentEntitiesByChildId(id, pageNumber - 1, pageSize, out var totalRecords, objectType);
|
||||
|
||||
return new PagedResult<EntityBasic>(totalRecords, pageNumber, pageSize)
|
||||
{
|
||||
@@ -987,7 +963,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
Id = rel.Id,
|
||||
Key = rel.Key,
|
||||
Udi = Udi.Create(udiEntity, rel.Key),
|
||||
Udi = Udi.Create(udiType, rel.Key),
|
||||
Icon = rel.ContentTypeIcon,
|
||||
Name = rel.Name,
|
||||
Alias = rel.ContentTypeAlias
|
||||
|
||||
Reference in New Issue
Block a user