Fix mapping records in nested namespaces (#8681) (#8682)

This commit is contained in:
Marek Dzikiewicz 2023-06-29 13:04:23 -04:00 committed by GitHub
parent 731b223f82
commit 05079efdd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,18 @@
using System;
namespace Orchard.Data {
/// <summary>
/// Marks whether a class should be mapped as an NHibernate record
/// </summary>
public class MapAsRecordAttribute : Attribute {
private readonly bool _enabled;
public MapAsRecordAttribute() : this(true) { }
public MapAsRecordAttribute(bool enabled) {
_enabled = enabled;
}
public bool Enabled => _enabled;
}
}

View File

@ -6,6 +6,7 @@ using System.Web.Mvc;
using Autofac.Core;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using Orchard.Data;
using Orchard.Environment.Configuration;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
@ -96,7 +97,7 @@ namespace Orchard.Environment.ShellBuilders {
}
var feature = availableFeatures[shellFeature];
foreach (var childDependency in ExpandDependenciesInternal(availableFeatures, feature.Dependencies, dependentFeatureDescriptor: feature))
yield return childDependency;
@ -197,7 +198,12 @@ namespace Orchard.Environment.ShellBuilders {
}
private static bool IsRecord(Type type) {
return ((type.Namespace ?? "").EndsWith(".Models") || (type.Namespace ?? "").EndsWith(".Records")) &&
var mapAsRecordAttr = type.GetCustomAttributes(typeof(MapAsRecordAttribute), false)
.OfType<MapAsRecordAttribute>()
.FirstOrDefault();
return ((type.Namespace ?? "").EndsWith(".Models") || (type.Namespace ?? "").EndsWith(".Records") || mapAsRecordAttr?.Enabled == true) &&
mapAsRecordAttr?.Enabled != false &&
type.GetProperty("Id") != null &&
(type.GetProperty("Id").GetAccessors()).All(x => x.IsVirtual) &&
!type.IsSealed &&

View File

@ -150,6 +150,7 @@
<ItemGroup>
<Compile Include="ContentManagement\Extensions\DriverResultExtensions.cs" />
<Compile Include="ContentManagement\Handlers\CloneContentContext.cs" />
<Compile Include="Data\MapAsRecordAttribute.cs" />
<Compile Include="Data\Migration\Interpreters\PostgreSqlCommandInterpreter.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapePlacementStrategy\DefaultPlacementParseMatchProviders.cs" />
<Compile Include="DisplayManagement\Descriptors\ShapePlacementStrategy\IPlacementParseMatchProvider.cs" />