File tree Expand file tree Collapse file tree 5 files changed +43
-57
lines changed
Async/NHSpecificTest/NH1845 Expand file tree Collapse file tree 5 files changed +43
-57
lines changed Original file line number Diff line number Diff line change 8
8
//------------------------------------------------------------------------------
9
9
10
10
11
- using NHibernate . Cfg . MappingSchema ;
12
- using NHibernate . Mapping . ByCode ;
13
11
using NUnit . Framework ;
14
12
namespace NHibernate . Test . NHSpecificTest . NH1845
15
13
{
16
14
using System . Threading . Tasks ;
17
15
using System . Threading ;
18
16
[ TestFixture ]
19
- public class FixtureAsync : TestCaseMappingByCode
17
+ public class FixtureAsync : BugTestCase
20
18
{
21
- protected override HbmMapping GetMappings ( )
22
- {
23
- var mapper = new ModelMapper ( ) ;
24
- mapper . Class < Category > ( rc =>
25
- {
26
- rc . Id ( x => x . Id , map => map . Generator ( Generators . Native ) ) ;
27
- rc . Property ( x => x . Name ) ;
28
- rc . ManyToOne ( x => x . Parent , map => map . Column ( "ParentId" ) ) ;
29
- rc . Bag ( x => x . Subcategories , map =>
30
- {
31
- map . Access ( Accessor . NoSetter ) ;
32
- map . Key ( km => km . Column ( "ParentId" ) ) ;
33
- map . Cascade ( Mapping . ByCode . Cascade . All . Include ( Mapping . ByCode . Cascade . DeleteOrphans ) ) ;
34
- } , rel => rel . OneToMany ( ) ) ;
35
- } ) ;
36
- var mappings = mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
37
- return mappings ;
38
- }
39
-
40
19
[ Test ]
41
20
public async Task LazyLoad_Initialize_AndEvictAsync ( )
42
21
{
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ public class Category
6
6
{
7
7
private readonly IList < Category > subcategories = new List < Category > ( ) ;
8
8
9
- public Category ( ) : this ( "" ) { }
9
+ public Category ( ) : this ( "" )
10
+ {
11
+ }
10
12
11
13
public Category ( string name )
12
14
{
@@ -17,6 +19,8 @@ public Category(string name)
17
19
18
20
public virtual string Name { get ; set ; }
19
21
22
+ public virtual int SortIndex { get ; set ; }
23
+
20
24
public virtual Category Parent { get ; set ; }
21
25
22
26
public virtual IList < Category > Subcategories
@@ -50,4 +54,4 @@ public override int GetHashCode()
50
54
return Name . GetHashCode ( ) ;
51
55
}
52
56
}
53
- }
57
+ }
Original file line number Diff line number Diff line change 1
- using NHibernate . Cfg . MappingSchema ;
2
- using NHibernate . Mapping . ByCode ;
3
1
using NUnit . Framework ;
4
2
namespace NHibernate . Test . NHSpecificTest . NH1845
5
3
{
6
4
[ TestFixture ]
7
- public class Fixture : TestCaseMappingByCode
5
+ public class Fixture : BugTestCase
8
6
{
9
- protected override HbmMapping GetMappings ( )
10
- {
11
- var mapper = new ModelMapper ( ) ;
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
- } ) ;
24
- var mappings = mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
25
- return mappings ;
26
- }
27
-
28
7
[ Test ]
29
8
public void LazyLoad_Initialize_AndEvict ( )
30
9
{
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <hibernate-mapping xmlns =" urn:nhibernate-mapping-2.2" assembly =" NHibernate.Test"
3
+ namespace =" NHibernate.Test.NHSpecificTest.NH1845"
4
+ default-cascade =" all" >
5
+ <class name =" Category" table =" Categories" lazy =" true"
6
+ dynamic-update =" true" select-before-update =" true" >
7
+
8
+ <id name =" Id" column =" Id" type =" Int32" unsaved-value =" 0" >
9
+ <generator class =" identity" />
10
+ </id >
11
+
12
+ <property name =" Name" />
13
+ <property name =" SortIndex" />
14
+
15
+ <many-to-one name =" Parent" column =" ParentCategoryId" class =" Category" not-null =" false" />
16
+
17
+ <list name =" Subcategories" cascade =" all" generic =" true" access =" nosetter.camelcase"
18
+ inverse =" true" lazy =" true" >
19
+ <key column =" ParentCategoryId" />
20
+ <index column =" SortIndex" />
21
+ <one-to-many class =" Category" />
22
+ </list >
23
+ </class >
24
+ </hibernate-mapping >
Original file line number Diff line number Diff line change @@ -443,18 +443,18 @@ public bool ContainsEntity(EntityKey key)
443
443
/// </summary>
444
444
public object RemoveEntity ( EntityKey key )
445
445
{
446
- if ( ! entitiesByKey . Remove ( key , out var tempObject ) )
447
- throw new KeyNotFoundException ( key . ToString ( ) ) ;
448
-
449
- object entity = tempObject ;
450
- List < EntityUniqueKey > toRemove = new List < EntityUniqueKey > ( ) ;
451
- foreach ( KeyValuePair < EntityUniqueKey , object > pair in entitiesByUniqueKey )
446
+ if ( entitiesByKey . Remove ( key , out var entity ) )
452
447
{
453
- if ( pair . Value == entity ) toRemove . Add ( pair . Key ) ;
454
- }
455
- foreach ( EntityUniqueKey uniqueKey in toRemove )
456
- {
457
- entitiesByUniqueKey . Remove ( uniqueKey ) ;
448
+ List < EntityUniqueKey > toRemove = new List < EntityUniqueKey > ( ) ;
449
+ foreach ( KeyValuePair < EntityUniqueKey , object > pair in entitiesByUniqueKey )
450
+ {
451
+ if ( pair . Value == entity ) toRemove . Add ( pair . Key ) ;
452
+ }
453
+
454
+ foreach ( EntityUniqueKey uniqueKey in toRemove )
455
+ {
456
+ entitiesByUniqueKey . Remove ( uniqueKey ) ;
457
+ }
458
458
}
459
459
460
460
entitySnapshotsByKey . Remove ( key ) ;
You can’t perform that action at this time.
0 commit comments