@@ -12,10 +12,18 @@ public class BadlyMappedEntity
1212 public virtual long SecondValue { get ; set ; }
1313 }
1414
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+
1523 [ TestFixture ]
1624 public class Fixture
1725 {
18- protected HbmMapping GetMappings ( )
26+ protected HbmMapping GetBadMappings ( )
1927 {
2028 var mapper = new ModelMapper ( ) ;
2129 mapper . Class < BadlyMappedEntity > (
@@ -42,7 +50,7 @@ protected HbmMapping GetMappings()
4250 [ Test ]
4351 public void ShouldThrowSoundErrorForBadlyMappedEntity ( )
4452 {
45- var mappings = GetMappings ( ) ;
53+ var mappings = GetBadMappings ( ) ;
4654 var cfg = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
4755 cfg . AddMapping ( mappings ) ;
4856
@@ -59,5 +67,60 @@ public void ShouldThrowSoundErrorForBadlyMappedEntity()
5967 factory ? . Dispose ( ) ;
6068 }
6169 }
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+ }
62125 }
63126}
0 commit comments