mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding AggregateAttribute to prefetch specific relationship
Applying AggregateAttribute on Tags for example --HG-- branch : 1.x
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.Tags.Models {
|
||||
public class ContentTagRecord {
|
||||
public virtual int Id { get; set; }
|
||||
|
||||
[Aggregate]
|
||||
public virtual TagRecord TagRecord { get; set; }
|
||||
|
||||
public virtual TagsPartRecord TagsPartRecord { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.Tags.Models {
|
||||
public class TagsPartRecord : ContentPartRecord {
|
||||
public TagsPartRecord() {
|
||||
Tags = new List<ContentTagRecord>();
|
||||
}
|
||||
|
||||
[Aggregate]
|
||||
public virtual IList<ContentTagRecord> Tags { get; set; }
|
||||
}
|
||||
}
|
||||
40
src/Orchard/Data/Conventions/AggregateAttribute.cs
Normal file
40
src/Orchard/Data/Conventions/AggregateAttribute.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using FluentNHibernate.Conventions;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
|
||||
namespace Orchard.Data.Conventions
|
||||
{
|
||||
/// <summary>
|
||||
/// This attribute is used to mark relationships which need to be eagerly fetched with the parent object,
|
||||
/// thus defining an aggregate in terms of DDD
|
||||
/// </summary>
|
||||
public class AggregateAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
public class ReferenceConvention : IReferenceConvention, IReferenceConventionAcceptance, IHasManyConvention, IHasManyConventionAcceptance
|
||||
{
|
||||
public void Apply(IManyToOneInstance instance)
|
||||
{
|
||||
instance.Fetch.Join();
|
||||
}
|
||||
|
||||
public void Accept(IAcceptanceCriteria<IManyToOneInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => x.Property != null && x.Property.IsDefined(typeof(AggregateAttribute), false));
|
||||
}
|
||||
|
||||
public void Apply(IOneToManyCollectionInstance instance)
|
||||
{
|
||||
instance.Fetch.Join();
|
||||
}
|
||||
|
||||
public void Accept(IAcceptanceCriteria<IOneToManyCollectionInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => x.Member != null && x.Member.IsDefined(typeof(AggregateAttribute), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@
|
||||
<Compile Include="ContentManagement\ImportContentSession.cs" />
|
||||
<Compile Include="ContentManagement\QueryHints.cs" />
|
||||
<Compile Include="ContentManagement\Utilities\ComputedField.cs" />
|
||||
<Compile Include="Data\Conventions\AggregateAttribute.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\PlacementInfo.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\StylesheetBindingStrategy.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user