@@ -56,14 +56,17 @@ public async VoidTask Fill(object entity, object owner, IDataReader reader, bool
56
56
public class CollectionObjectFitter : IFitter
57
57
{
58
58
IObjectActivator _elementActivator ;
59
- IEntityRowComparer _entityRowComparer ;
59
+ IEntityKey _entityKey ;
60
60
IFitter _elementFitter ;
61
61
PropertyDescriptor _elementOwnerProperty ;
62
62
63
- public CollectionObjectFitter ( IObjectActivator elementActivator , IEntityRowComparer entityRowComparer , IFitter elementFitter , PropertyDescriptor elementOwnerProperty )
63
+ HashSet < object > _keySet = new HashSet < object > ( ) ;
64
+ object _collection ;
65
+
66
+ public CollectionObjectFitter ( IObjectActivator elementActivator , IEntityKey entityKey , IFitter elementFitter , PropertyDescriptor elementOwnerProperty )
64
67
{
65
68
this . _elementActivator = elementActivator ;
66
- this . _entityRowComparer = entityRowComparer ;
69
+ this . _entityKey = entityKey ;
67
70
this . _elementFitter = elementFitter ;
68
71
this . _elementOwnerProperty = elementOwnerProperty ;
69
72
}
@@ -76,24 +79,33 @@ public void Prepare(IDataReader reader)
76
79
77
80
public async VoidTask Fill ( object collection , object owner , IDataReader reader , bool @async )
78
81
{
82
+ if ( this . _collection != collection )
83
+ {
84
+ this . _keySet . Clear ( ) ;
85
+ this . _collection = collection ;
86
+ }
87
+
79
88
IList entityContainer = collection as IList ;
80
89
81
90
object entity = null ;
82
- if ( entityContainer . Count > 0 )
83
- entity = entityContainer [ entityContainer . Count - 1 ] ;
84
91
85
- if ( entity == null || ! this . _entityRowComparer . IsEntityRow ( entity , reader ) )
92
+ var keyValue = this . _entityKey . GetKeyValue ( reader ) ;
93
+ if ( ! this . _keySet . Contains ( keyValue ) )
86
94
{
87
95
entity = await this . _elementActivator . CreateInstance ( reader , @async ) ;
88
-
89
- if ( entity == null )
90
- return ;
91
-
92
- this . _elementOwnerProperty . SetValue ( entity , owner ) ; //entity.XX = owner
93
- entityContainer . Add ( entity ) ;
96
+ if ( entity != null )
97
+ {
98
+ this . _elementOwnerProperty . SetValue ( entity , owner ) ; //entity.XX = owner
99
+ entityContainer . Add ( entity ) ;
100
+ this . _keySet . Add ( keyValue ) ;
101
+ }
94
102
}
95
103
96
- await this . _elementFitter . Fill ( entity , null , reader , @async ) ;
104
+ if ( entityContainer . Count > 0 )
105
+ {
106
+ entity = entityContainer [ entityContainer . Count - 1 ] ;
107
+ await this . _elementFitter . Fill ( entity , null , reader , @async ) ;
108
+ }
97
109
}
98
110
}
99
111
}
0 commit comments