@@ -12,10 +12,18 @@ public class BadlyMappedEntity
12
12
public virtual long SecondValue { get ; set ; }
13
13
}
14
14
15
+ public class EntityWithReadOnlyPropertiesDuplicatingColumns
16
+ {
17
+ public virtual Guid Id { get ; set ; }
18
+ public virtual Guid IdCopy { get ; set ; }
19
+ // Just to "emulate" a pseudo one-to-one while not actually having another entity to map.
20
+ public virtual EntityWithReadOnlyPropertiesDuplicatingColumns Self { get ; set ; }
21
+ }
22
+
15
23
[ TestFixture ]
16
24
public class Fixture
17
25
{
18
- protected HbmMapping GetMappings ( )
26
+ protected HbmMapping GetBadMappings ( )
19
27
{
20
28
var mapper = new ModelMapper ( ) ;
21
29
mapper . Class < BadlyMappedEntity > (
@@ -42,7 +50,7 @@ protected HbmMapping GetMappings()
42
50
[ Test ]
43
51
public void ShouldThrowSoundErrorForBadlyMappedEntity ( )
44
52
{
45
- var mappings = GetMappings ( ) ;
53
+ var mappings = GetBadMappings ( ) ;
46
54
var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
47
55
cfg . AddMapping ( mappings ) ;
48
56
@@ -59,5 +67,60 @@ public void ShouldThrowSoundErrorForBadlyMappedEntity()
59
67
factory ? . Dispose ( ) ;
60
68
}
61
69
}
70
+
71
+ protected HbmMapping GetValidMappings ( )
72
+ {
73
+ var mapper = new ModelMapper ( ) ;
74
+ mapper . Class < EntityWithReadOnlyPropertiesDuplicatingColumns > (
75
+ ca =>
76
+ {
77
+ ca . Abstract ( true ) ;
78
+ ca . Id (
79
+ x => x . Id ,
80
+ map =>
81
+ {
82
+ map . Column ( "EntityId" ) ;
83
+ map . Generator ( Generators . GuidComb ) ;
84
+ } ) ;
85
+ ca . ManyToOne (
86
+ x => x . Self ,
87
+ map =>
88
+ {
89
+ map . Column ( "EntityId" ) ;
90
+ map . Update ( false ) ;
91
+ map . Insert ( false ) ;
92
+ } ) ;
93
+ ca . Property (
94
+ x => x . IdCopy ,
95
+ map =>
96
+ {
97
+ map . Column ( "EntityId" ) ;
98
+ map . Update ( false ) ;
99
+ map . Insert ( false ) ;
100
+ } ) ;
101
+ } ) ;
102
+
103
+ return mapper . CompileMappingFor ( new [ ] { typeof ( BadlyMappedEntity ) } ) ;
104
+ }
105
+
106
+ [ Test ]
107
+ public void ShouldAcceptReadOnlyPropertiesDuplicatingAColumn ( )
108
+ {
109
+ var mappings = GetValidMappings ( ) ;
110
+ var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
111
+ cfg . AddMapping ( mappings ) ;
112
+
113
+ ISessionFactory factory = null ;
114
+ try
115
+ {
116
+ Assert . That (
117
+ ( ) => factory = cfg . BuildSessionFactory ( ) ,
118
+ Throws . Nothing ) ;
119
+ }
120
+ finally
121
+ {
122
+ factory ? . Dispose ( ) ;
123
+ }
124
+ }
62
125
}
63
126
}
0 commit comments