3
3
using NUnit . Framework ;
4
4
namespace NHibernate . Test . NHSpecificTest . NH1845
5
5
{
6
- public class Fixture : TestCaseMappingByCode
6
+ public class Fixture : TestCaseMappingByCode
7
7
{
8
8
9
9
protected override HbmMapping GetMappings ( )
10
10
{
11
11
var mapper = new ModelMapper ( ) ;
12
12
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
+ } ) ;
24
24
var mappings = mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
25
25
return mappings ;
26
26
}
@@ -44,6 +44,9 @@ public void LazyLoad_Initialize_AndEvict()
44
44
using ( ISession session = OpenSession ( ) )
45
45
using ( ITransaction transaction = session . BeginTransaction ( ) )
46
46
{
47
+ // first delete children
48
+ session . CreateQuery ( "delete from Category where Parent != null" ) . ExecuteUpdate ( ) ;
49
+ // then the rest
47
50
session . CreateQuery ( "delete from Category" ) . ExecuteUpdate ( ) ;
48
51
transaction . Commit ( ) ;
49
52
}
0 commit comments