Skip to content

Commit 6c596b2

Browse files
committed
delete children first then the rest
1 parent 0bf6e35 commit 6c596b2

File tree

1 file changed

+15
-12
lines changed
  • src/NHibernate.Test/NHSpecificTest/NH1845

1 file changed

+15
-12
lines changed

src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
using NUnit.Framework;
44
namespace NHibernate.Test.NHSpecificTest.NH1845
55
{
6-
public class Fixture: TestCaseMappingByCode
6+
public class Fixture : TestCaseMappingByCode
77
{
88

99
protected override HbmMapping GetMappings()
1010
{
1111
var mapper = new ModelMapper();
1212
mapper.Class<Category>(rc =>
13-
{
14-
rc.Id(x=> x.Id, map=> map.Generator(Generators.Native));
15-
rc.Property(x=> x.Name);
16-
rc.ManyToOne(x=> x.Parent, map=> map.Column("ParentId"));
17-
rc.Bag(x => x.Subcategories, map =>
18-
{
19-
map.Access(Accessor.NoSetter);
20-
map.Key(km=> km.Column("ParentId"));
21-
map.Cascade(Mapping.ByCode.Cascade.All.Include(Mapping.ByCode.Cascade.DeleteOrphans));
22-
}, rel => rel.OneToMany());
23-
});
13+
{
14+
rc.Id(x => x.Id, map => map.Generator(Generators.Native));
15+
rc.Property(x => x.Name);
16+
rc.ManyToOne(x => x.Parent, map => map.Column("ParentId"));
17+
rc.Bag(x => x.Subcategories, map =>
18+
{
19+
map.Access(Accessor.NoSetter);
20+
map.Key(km => km.Column("ParentId"));
21+
map.Cascade(Mapping.ByCode.Cascade.All.Include(Mapping.ByCode.Cascade.DeleteOrphans));
22+
}, rel => rel.OneToMany());
23+
});
2424
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
2525
return mappings;
2626
}
@@ -44,6 +44,9 @@ public void LazyLoad_Initialize_AndEvict()
4444
using (ISession session = OpenSession())
4545
using (ITransaction transaction = session.BeginTransaction())
4646
{
47+
// first delete children
48+
session.CreateQuery("delete from Category where Parent != null").ExecuteUpdate();
49+
// then the rest
4750
session.CreateQuery("delete from Category").ExecuteUpdate();
4851
transaction.Commit();
4952
}

0 commit comments

Comments
 (0)