33using NUnit . Framework ;
44namespace 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