diff --git a/src/FluentNHibernate.Testing/FluentInterfaceTests/AnyMutablePropertyModelGenerationTests.cs b/src/FluentNHibernate.Testing/FluentInterfaceTests/AnyMutablePropertyModelGenerationTests.cs index 7b420063c..5ebebcd9b 100644 --- a/src/FluentNHibernate.Testing/FluentInterfaceTests/AnyMutablePropertyModelGenerationTests.cs +++ b/src/FluentNHibernate.Testing/FluentInterfaceTests/AnyMutablePropertyModelGenerationTests.cs @@ -33,6 +33,18 @@ public void CascadeSetsModelCascadePropertyToValue() .ModelShouldMatch(x => x.Cascade.ShouldEqual("all")); } + [Test] + public void CascadeAppendModelCascadePropertyToValue() + { + Any() + .Mapping(m => m + .IdentityType() + .EntityIdentifierColumn("col") + .EntityTypeColumn("col2") + .Cascade.Merge().Cascade.SaveUpdate()) + .ModelShouldMatch(x => x.Cascade.ShouldEqual("merge,save-update")); + } + [Test] public void IdentityTypeSetsModelIdTypePropertyToPropertyTypeName() { diff --git a/src/FluentNHibernate.Testing/FluentInterfaceTests/HibernateMappingMutablePropertyModelGenerationTests.cs b/src/FluentNHibernate.Testing/FluentInterfaceTests/HibernateMappingMutablePropertyModelGenerationTests.cs index c0c943957..747789552 100644 --- a/src/FluentNHibernate.Testing/FluentInterfaceTests/HibernateMappingMutablePropertyModelGenerationTests.cs +++ b/src/FluentNHibernate.Testing/FluentInterfaceTests/HibernateMappingMutablePropertyModelGenerationTests.cs @@ -37,6 +37,14 @@ public void DefaultCascadeShouldSetModelDefaultCascadePropertyToValue() .ModelShouldMatch(x => x.DefaultCascade.ShouldEqual("all")); } + [Test] + public void DefaultCascadeShouldAppendModelDefaultCascadePropertyToValue() + { + HibernateMapping() + .Mapping(m => { m.DefaultCascade.Merge(); m.DefaultCascade.SaveUpdate(); }) + .ModelShouldMatch(x => x.DefaultCascade.ShouldEqual("merge,save-update")); + } + [Test] public void DefaultLazyShouldSetModelDefaultLazyPropertyToTrue() { diff --git a/src/FluentNHibernate.Testing/FluentInterfaceTests/ManyToManyMutablePropertyModelGenerationTests.cs b/src/FluentNHibernate.Testing/FluentInterfaceTests/ManyToManyMutablePropertyModelGenerationTests.cs index b78aa9de8..edc17a8b9 100644 --- a/src/FluentNHibernate.Testing/FluentInterfaceTests/ManyToManyMutablePropertyModelGenerationTests.cs +++ b/src/FluentNHibernate.Testing/FluentInterfaceTests/ManyToManyMutablePropertyModelGenerationTests.cs @@ -52,6 +52,14 @@ public void CascadeShouldSetModelCascadePropertyToValue() .ModelShouldMatch(x => x.Cascade.ShouldEqual("all")); } + [Test] + public void CascadeShouldAppendModelCascadePropertyToValue() + { + ManyToMany(x => x.BagOfChildren) + .Mapping(m => { m.Cascade.SaveUpdate(); m.Cascade.Merge(); }) + .ModelShouldMatch(x => x.Cascade.ShouldEqual("save-update,merge")); + } + [Test] public void CollectionTypeShouldSetModelCollectionTypePropertyToValue() { diff --git a/src/FluentNHibernate.Testing/FluentInterfaceTests/OneToOneMutablePropertyModelGenerationTests.cs b/src/FluentNHibernate.Testing/FluentInterfaceTests/OneToOneMutablePropertyModelGenerationTests.cs index 69ed3fefe..298112228 100644 --- a/src/FluentNHibernate.Testing/FluentInterfaceTests/OneToOneMutablePropertyModelGenerationTests.cs +++ b/src/FluentNHibernate.Testing/FluentInterfaceTests/OneToOneMutablePropertyModelGenerationTests.cs @@ -33,7 +33,7 @@ public void ClassShouldSetModelClassPropertyToValue() } [Test] - public void CascadeShouldSetModelCascadePropertyToTrue() + public void ConstrainedShouldSetModelConstrainedPropertyToTrue() { OneToOne() .Mapping(m => m.Constrained()) @@ -41,13 +41,29 @@ public void CascadeShouldSetModelCascadePropertyToTrue() } [Test] - public void NotCascadeShouldSetModelCascadePropertyToFalse() + public void NotConstrainedShouldSetModelConstrainedPropertyToFalse() { OneToOne() .Mapping(m => m.Not.Constrained()) .ModelShouldMatch(x => x.Constrained.ShouldBeFalse()); } + [Test] + public void CascadeSetsModelCascadePropertyToValue() + { + OneToOne() + .Mapping(m => m.Cascade.All()) + .ModelShouldMatch(x => x.Cascade.ShouldEqual("all")); + } + + [Test] + public void CascadeAppendModelCascadePropertyToValue() + { + OneToOne() + .Mapping(m => { m.Cascade.Merge(); m.Cascade.SaveUpdate(); }) + .ModelShouldMatch(x => x.Cascade.ShouldEqual("merge,save-update")); + } + [Test] public void FetchShouldSetModelFetchPropertyToValue() { diff --git a/src/FluentNHibernate/Mapping/AnyPart.cs b/src/FluentNHibernate/Mapping/AnyPart.cs index b5f6cf241..d1934bfcb 100644 --- a/src/FluentNHibernate/Mapping/AnyPart.cs +++ b/src/FluentNHibernate/Mapping/AnyPart.cs @@ -31,7 +31,11 @@ public AnyPart(Type entity, Member member) this.entity = entity; this.member = member; access = new AccessStrategyBuilder>(this, value => attributes.Set("Access", Layer.UserSupplied, value)); - cascade = new CascadeExpression>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value)); + cascade = new CascadeExpression>(this, value => + { + var current = attributes.Get("Cascade") as string; + attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value)); + }); SetDefaultAccess(); } diff --git a/src/FluentNHibernate/Mapping/HibernateMappingPart.cs b/src/FluentNHibernate/Mapping/HibernateMappingPart.cs index 6eb6b4231..bbe7a3a37 100644 --- a/src/FluentNHibernate/Mapping/HibernateMappingPart.cs +++ b/src/FluentNHibernate/Mapping/HibernateMappingPart.cs @@ -13,7 +13,11 @@ public class HibernateMappingPart : IHibernateMappingProvider public HibernateMappingPart() { - defaultCascade = new CascadeExpression(this, value => attributes.Set("DefaultCascade", Layer.UserSupplied, value)); + defaultCascade = new CascadeExpression(this, value => + { + var current = attributes.Get("DefaultCascade") as string; + attributes.Set("DefaultCascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value)); + }); defaultAccess = new AccessStrategyBuilder(this, value => attributes.Set("DefaultAccess", Layer.UserSupplied, value)); } diff --git a/src/FluentNHibernate/Mapping/OneToManyPart.cs b/src/FluentNHibernate/Mapping/OneToManyPart.cs index 9d3385a75..cbeedbce2 100644 --- a/src/FluentNHibernate/Mapping/OneToManyPart.cs +++ b/src/FluentNHibernate/Mapping/OneToManyPart.cs @@ -12,7 +12,6 @@ public class OneToManyPart : ToManyBase, TChild> { private readonly Type entity; private readonly ColumnMappingCollection> keyColumns; - private readonly CollectionCascadeExpression> cascade; private readonly NotFoundExpression> notFound; private IndexManyToManyPart manyToManyIndex; private readonly Type childType; @@ -31,11 +30,6 @@ protected OneToManyPart(Type entity, Member member, Type collectionType) childType = collectionType; keyColumns = new ColumnMappingCollection>(this); - cascade = new CollectionCascadeExpression>(this, value => - { - var current = collectionAttributes.Get("Cascade") as string; - collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value)); - }); notFound = new NotFoundExpression>(this, value => relationshipAttributes.Set("NotFound", Layer.UserSupplied, value)); collectionAttributes.Set("Name", Layer.Defaults, member.Name); @@ -54,7 +48,7 @@ public NotFoundExpression> NotFound /// public new CollectionCascadeExpression> Cascade { - get { return cascade; } + get { return base.Cascade; } } /// diff --git a/src/FluentNHibernate/Mapping/OneToOnePart.cs b/src/FluentNHibernate/Mapping/OneToOnePart.cs index f9f72bb50..ac6d1a629 100644 --- a/src/FluentNHibernate/Mapping/OneToOnePart.cs +++ b/src/FluentNHibernate/Mapping/OneToOnePart.cs @@ -21,7 +21,11 @@ public OneToOnePart(Type entity, Member member) { access = new AccessStrategyBuilder>(this, value => attributes.Set("Access", Layer.UserSupplied, value)); fetch = new FetchTypeExpression>(this, value => attributes.Set("Fetch", Layer.UserSupplied, value)); - cascade = new CascadeExpression>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value)); + cascade = new CascadeExpression>(this, value => + { + var current = attributes.Get("Cascade") as string; + attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value)); + }); this.entity = entity; this.member = member; diff --git a/src/FluentNHibernate/Mapping/ToManyBase.cs b/src/FluentNHibernate/Mapping/ToManyBase.cs index 83bd20fc2..060094817 100644 --- a/src/FluentNHibernate/Mapping/ToManyBase.cs +++ b/src/FluentNHibernate/Mapping/ToManyBase.cs @@ -36,7 +36,11 @@ protected ToManyBase(Type entity, Member member, Type type) AsBag(); access = new AccessStrategyBuilder((T)this, value => collectionAttributes.Set("Access", Layer.UserSupplied, value)); fetch = new FetchTypeExpression((T)this, value => collectionAttributes.Set("Fetch", Layer.UserSupplied, value)); - cascade = new CollectionCascadeExpression((T)this, value => collectionAttributes.Set("Cascade", Layer.UserSupplied, value)); + cascade = new CollectionCascadeExpression((T)this, value => + { + var current = collectionAttributes.Get("Cascade") as string; + collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value)); + }); SetDefaultCollectionType(); SetCustomCollectionType(type);