narsil/Tanshu.Accounts.Repository/Fluent/CascadeConvention.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

28 lines
931 B
C#

using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;
using System.Diagnostics;
namespace Tanshu.Accounts.SqlDAO
{
public class CascadeConvention : IHasManyConvention, IReferenceConvention
{
public void Apply(IManyToOneInstance instance)
{
var property = instance.Property;
if (!AttributeChecker.Cascade(property.MemberInfo)) return;
Trace.TraceInformation("CascadeAll on {0}.{1}", property.DeclaringType.Name, property.Name);
instance.Cascade.All();
}
public void Apply(IOneToManyCollectionInstance instance)
{
var property = instance.Member;
if (!AttributeChecker.Cascade(property)) return;
Trace.TraceInformation("CascadeAllDeleteOrphan on {0}.{1}", property.DeclaringType.Name, property.Name);
instance.Cascade.AllDeleteOrphan();
}
}
}