2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Linq . Expressions ;
5
- using System . Reflection ;
6
5
using FluentNHibernate . Mapping ;
7
6
using FluentNHibernate . Mapping . Providers ;
7
+ using FluentNHibernate . MappingModel ;
8
8
using FluentNHibernate . MappingModel . ClassBased ;
9
9
using FluentNHibernate . Utils ;
10
10
11
11
namespace FluentNHibernate . Automapping
12
12
{
13
- #pragma warning disable 612 , 618 , 672
14
13
public class AutoMapping < T > : ClassMap < T > , IAutoClasslike , IPropertyIgnorer
15
14
{
15
+ private readonly AttributeStore < ClassMapping > attributes ;
16
+ private readonly MappingProviderStore providers ;
16
17
readonly IList < Member > mappedMembers ;
17
18
18
19
public AutoMapping ( IList < Member > mappedMembers )
20
+ : this ( mappedMembers , new AttributeStore < ClassMapping > ( ) , new MappingProviderStore ( ) )
21
+ { }
22
+
23
+ AutoMapping ( IList < Member > mappedMembers , AttributeStore < ClassMapping > attributes , MappingProviderStore providers )
24
+ : base ( attributes , providers )
19
25
{
20
26
this . mappedMembers = mappedMembers ;
27
+ this . attributes = attributes ;
28
+ this . providers = providers ;
21
29
}
22
30
23
31
void IAutoClasslike . DiscriminateSubClassesOnColumn ( string column )
@@ -38,52 +46,53 @@ void IAutoClasslike.AlterModel(ClassMappingBase mapping)
38
46
{
39
47
var classMapping = ( ClassMapping ) mapping ;
40
48
41
- if ( id != null )
42
- classMapping . Id = id . GetIdentityMapping ( ) ;
49
+ if ( providers . Id != null )
50
+ classMapping . Id = providers . Id . GetIdentityMapping ( ) ;
43
51
44
- if ( compositeId != null )
45
- classMapping . Id = compositeId . GetCompositeIdMapping ( ) ;
52
+ if ( providers . CompositeId != null )
53
+ classMapping . Id = providers . CompositeId . GetCompositeIdMapping ( ) ;
46
54
47
- if ( version != null )
48
- classMapping . Version = version . GetVersionMapping ( ) ;
55
+ if ( providers . Version != null )
56
+ classMapping . Version = providers . Version . GetVersionMapping ( ) ;
49
57
50
- if ( discriminator != null )
51
- classMapping . Discriminator = ( ( IDiscriminatorMappingProvider ) discriminator ) . GetDiscriminatorMapping ( ) ;
58
+ if ( providers . Discriminator != null )
59
+ classMapping . Discriminator = providers . Discriminator . GetDiscriminatorMapping ( ) ;
52
60
53
61
if ( Cache . IsDirty )
54
62
classMapping . Cache = ( ( ICacheMappingProvider ) Cache ) . GetCacheMapping ( ) ;
55
63
56
- foreach ( var join in joins )
57
- classMapping . AddJoin ( join ) ;
64
+ foreach ( var join in providers . Joins )
65
+ classMapping . AddJoin ( join . GetJoinMapping ( ) ) ;
58
66
59
- classMapping . Tuplizer = tuplizerMapping ;
67
+ classMapping . Tuplizer = providers . TuplizerMapping ;
60
68
}
61
69
62
- foreach ( var property in Properties )
70
+ foreach ( var property in providers . Properties )
63
71
mapping . AddOrReplaceProperty ( property . GetPropertyMapping ( ) ) ;
64
72
65
- foreach ( var collection in collections )
73
+ foreach ( var collection in providers . Collections )
66
74
mapping . AddOrReplaceCollection ( collection . GetCollectionMapping ( ) ) ;
67
75
68
- foreach ( var component in Components )
76
+ foreach ( var component in providers . Components )
69
77
mapping . AddOrReplaceComponent ( component . GetComponentMapping ( ) ) ;
70
78
71
- foreach ( var oneToOne in oneToOnes )
79
+ foreach ( var oneToOne in providers . OneToOnes )
72
80
mapping . AddOrReplaceOneToOne ( oneToOne . GetOneToOneMapping ( ) ) ;
73
81
74
- foreach ( var reference in references )
82
+ foreach ( var reference in providers . References )
75
83
mapping . AddOrReplaceReference ( reference . GetManyToOneMapping ( ) ) ;
76
84
77
- foreach ( var any in anys )
85
+ foreach ( var any in providers . Anys )
78
86
mapping . AddOrReplaceAny ( any . GetAnyMapping ( ) ) ;
79
87
80
- foreach ( var storedProcedure in storedProcedures )
88
+ foreach ( var storedProcedure in providers . StoredProcedures )
81
89
mapping . AddStoredProcedure ( storedProcedure . GetStoredProcedureMapping ( ) ) ;
82
90
83
- foreach ( var filter in filters )
91
+ foreach ( var filter in providers . Filters )
84
92
mapping . AddOrReplaceFilter ( filter . GetFilterMapping ( ) ) ;
85
93
}
86
94
95
+ [ Obsolete ( "Do not call this method. Implementation detail mistakenly made public. Will be made private in next version." ) ]
87
96
protected override OneToManyPart < TChild > HasMany < TChild > ( Member property )
88
97
{
89
98
mappedMembers . Add ( property ) ;
@@ -131,29 +140,33 @@ public override CompositeIdentityPart<T> CompositeId()
131
140
{
132
141
var part = new AutoCompositeIdentityPart < T > ( mappedMembers ) ;
133
142
134
- compositeId = part ;
143
+ providers . CompositeId = part ;
135
144
136
145
return part ;
137
146
}
138
147
148
+ [ Obsolete ( "Do not call this method. Implementation detail mistakenly made public. Will be made private in next version." ) ]
139
149
protected override PropertyPart Map ( Member property , string columnName )
140
150
{
141
151
mappedMembers . Add ( property ) ;
142
152
return base . Map ( property , columnName ) ;
143
153
}
144
154
155
+ [ Obsolete ( "Do not call this method. Implementation detail mistakenly made public. Will be made private in next version." ) ]
145
156
protected override ManyToOnePart < TOther > References < TOther > ( Member property , string columnName )
146
157
{
147
158
mappedMembers . Add ( property ) ;
148
159
return base . References < TOther > ( property , columnName ) ;
149
160
}
150
161
162
+ [ Obsolete ( "Do not call this method. Implementation detail mistakenly made public. Will be made private in next version." ) ]
151
163
protected override ManyToManyPart < TChild > HasManyToMany < TChild > ( Member property )
152
164
{
153
165
mappedMembers . Add ( property ) ;
154
166
return base . HasManyToMany < TChild > ( property ) ;
155
167
}
156
168
169
+ [ Obsolete ( "Do not call this method. Implementation detail mistakenly made public. Will be made private in next version." ) ]
157
170
protected override ComponentPart < TComponent > Component < TComponent > ( Member property , Action < ComponentPart < TComponent > > action )
158
171
{
159
172
mappedMembers . Add ( property ) ;
@@ -170,6 +183,7 @@ public override IdentityPart Id(Expression<Func<T, object>> memberExpression, st
170
183
return base . Id ( memberExpression , column ) ;
171
184
}
172
185
186
+ [ Obsolete ( "Do not call this method. Implementation detail mistakenly made public. Will be made private in next version." ) ]
173
187
protected override OneToOnePart < TOther > HasOne < TOther > ( Member property )
174
188
{
175
189
mappedMembers . Add ( property ) ;
@@ -191,7 +205,7 @@ public AutoJoinedSubClassPart<TSubclass> JoinedSubClass<TSubclass>(string keyCol
191
205
if ( action != null )
192
206
action ( joinedclass ) ;
193
207
194
- subclasses [ typeof ( TSubclass ) ] = joinedclass ;
208
+ providers . Subclasses [ typeof ( TSubclass ) ] = joinedclass ;
195
209
196
210
return joinedclass ;
197
211
}
@@ -202,7 +216,7 @@ public IAutoClasslike JoinedSubClass(Type type, string keyColumn)
202
216
var joinedclass = ( ISubclassMappingProvider ) Activator . CreateInstance ( genericType , keyColumn ) ;
203
217
204
218
// remove any mappings for the same type, then re-add
205
- subclasses [ type ] = joinedclass ;
219
+ providers . Subclasses [ type ] = joinedclass ;
206
220
207
221
return ( IAutoClasslike ) joinedclass ;
208
222
}
@@ -223,7 +237,7 @@ public AutoSubClassPart<TSubclass> SubClass<TSubclass>(object discriminatorValue
223
237
action ( subclass ) ;
224
238
225
239
// remove any mappings for the same type, then re-add
226
- subclasses [ typeof ( TSubclass ) ] = subclass ;
240
+ providers . Subclasses [ typeof ( TSubclass ) ] = subclass ;
227
241
228
242
return subclass ;
229
243
}
@@ -240,7 +254,7 @@ public IAutoClasslike SubClass(Type type, string discriminatorValue)
240
254
var subclass = ( ISubclassMappingProvider ) Activator . CreateInstance ( genericType , null , discriminatorValue ) ;
241
255
242
256
// remove any mappings for the same type, then re-add
243
- subclasses [ type ] = subclass ;
257
+ providers . Subclasses [ type ] = subclass ;
244
258
245
259
return ( IAutoClasslike ) subclass ;
246
260
}
@@ -255,7 +269,7 @@ public void Join(string table, Action<AutoJoinPart<T>> action)
255
269
256
270
action ( join ) ;
257
271
258
- joins . Add ( ( ( IJoinMappingProvider ) join ) . GetJoinMapping ( ) ) ;
272
+ providers . Joins . Add ( join ) ;
259
273
}
260
274
261
275
#pragma warning disable 809
@@ -266,6 +280,5 @@ public override ImportPart ImportType<TImport>()
266
280
return null ;
267
281
}
268
282
#pragma warning restore 809
269
- #pragma warning restore 612 , 618 , 672
270
283
}
271
284
}
0 commit comments