Adding AggregateAttribute to prefetch specific relationship

Applying AggregateAttribute on Tags for example

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-09-10 10:40:21 -07:00
parent cab247320a
commit 2ac7d8b8c1
4 changed files with 49 additions and 0 deletions

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View 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));
}
}
}

View File

@@ -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" />