File tree Expand file tree Collapse file tree 7 files changed +65
-54
lines changed
NHibernate/Cfg/MappingSchema
NHibernate.Test/NHSpecificTest/NH1007 Expand file tree Collapse file tree 7 files changed +65
-54
lines changed Original file line number Diff line number Diff line change 6
6
<property name =" Name" />
7
7
</class >
8
8
9
- <!--
10
- Mapping to demonstrate that the 'column' attribute takes precedence over a 'column' element - and, for consistency,
11
- the same behaviour applies to the generator attribute/element
9
+ <!--
10
+ Mapping to demonstrate that the 'generator' attribute takes precedence over a 'generator' element
12
11
-->
13
12
<class name =" Employer2" >
14
13
<id name =" Id" generator =" guid" >
15
14
<generator class =" invalid_generator_class" />
16
15
</id >
17
-
18
- <property name =" Name" column =" Name" >
19
- <column name =" InvalidColumnName" />
20
- </property >
16
+
17
+ <property name =" Name" />
21
18
</class >
22
19
23
- </hibernate-mapping >
20
+ </hibernate-mapping >
Original file line number Diff line number Diff line change @@ -80,14 +80,15 @@ public IEnumerable<object> ColumnsAndFormulas
80
80
{
81
81
get
82
82
{
83
- if ( Items != null )
84
- return Items ;
85
- // Avoid a possible breaking change for mapping having left a column attribute along with a formula one.
86
- // This is a mapping error, but previous implementation was silently ignoring the column attribute in
87
- // such case.
88
- if ( ! string . IsNullOrEmpty ( formula ) )
89
- return AsFormulas ( ) ;
90
- return AsColumns ( ) ;
83
+ if ( Items != null && ( ! string . IsNullOrEmpty ( column ) || ! string . IsNullOrEmpty ( formula ) ) )
84
+ throw new MappingException (
85
+ $ "On an element: specifying columns or formulas with both attributes and xml sub-elements is " +
86
+ $ "invalid. Please use only xml sub-elements, or only one of them as attribute") ;
87
+ if ( ! string . IsNullOrEmpty ( column ) && ! string . IsNullOrEmpty ( formula ) )
88
+ throw new MappingException (
89
+ $ "On an element: specifying both column and formula attributes is invalid. Please " +
90
+ $ "specify only one of them, or use xml sub-elements") ;
91
+ return Items ?? AsColumns ( ) . Cast < object > ( ) . Concat ( AsFormulas ( ) . Cast < object > ( ) ) ;
91
92
}
92
93
}
93
94
}
Original file line number Diff line number Diff line change @@ -83,14 +83,16 @@ public IEnumerable<object> ColumnsAndFormulas
83
83
{
84
84
get
85
85
{
86
- if ( Items != null )
87
- return Items ;
88
- // Avoid a possible breaking change for mapping having left a column attribute along with a formula one.
89
- // This is a mapping error, but previous implementation was silently ignoring the column attribute in
90
- // such case.
91
- if ( ! string . IsNullOrEmpty ( formula ) )
92
- return AsFormulas ( ) ;
93
- return AsColumns ( ) ;
86
+ if ( Items != null && ( ! string . IsNullOrEmpty ( column ) || ! string . IsNullOrEmpty ( formula ) ) )
87
+ throw new MappingException (
88
+ $ "On a many-to-many targeting { EntityName } : specifying columns or formulas with both " +
89
+ $ "attributes and sub-elements is invalid. Please use only sub-elements, or only one of them " +
90
+ $ "as attribute") ;
91
+ if ( ! string . IsNullOrEmpty ( column ) && ! string . IsNullOrEmpty ( formula ) )
92
+ throw new MappingException (
93
+ $ "On a many-to-many targeting { EntityName } : specifying both column and formula attributes is " +
94
+ $ "invalid. Please specify only one of them, or use sub-elements") ;
95
+ return Items ?? AsColumns ( ) . Cast < object > ( ) . Concat ( AsFormulas ( ) . Cast < object > ( ) ) ;
94
96
}
95
97
}
96
98
}
Original file line number Diff line number Diff line change @@ -118,16 +118,23 @@ public HbmNotFoundMode NotFoundMode
118
118
[ XmlIgnore ]
119
119
public IEnumerable < object > ColumnsAndFormulas
120
120
{
121
- // when Items is empty the column attribute AND formula attribute will be used
122
- // and it may cause an issue (breaking change)
123
- // On the other hand it work properly when a mixing between <formula> and <column> tags are used
124
- // respecting the order used in the mapping to map multi-columns id.
125
- get { return Items ?? Columns . Cast < object > ( ) . Concat ( Formulas . Cast < object > ( ) ) ; }
121
+ get
122
+ {
123
+ if ( Items != null && ( ! string . IsNullOrEmpty ( column ) || ! string . IsNullOrEmpty ( formula ) ) )
124
+ throw new MappingException (
125
+ $ "On { Name } many-to-one: specifying columns or formulas with both attributes and " +
126
+ $ "sub-elements is invalid. Please use only sub-elements, or only one of them as attribute") ;
127
+ if ( ! string . IsNullOrEmpty ( column ) && ! string . IsNullOrEmpty ( formula ) )
128
+ throw new MappingException (
129
+ $ "On { Name } many-to-one: specifying both column and formula attributes is invalid. Please " +
130
+ $ "specify only one of them, or use sub-elements") ;
131
+ return Items ?? AsColumns ( ) . Cast < object > ( ) . Concat ( AsFormulas ( ) . Cast < object > ( ) ) ;
132
+ }
126
133
}
127
134
128
135
public HbmLaziness ? Lazy
129
136
{
130
137
get { return lazySpecified ? lazy : ( HbmLaziness ? ) null ; }
131
138
}
132
139
}
133
- }
140
+ }
Original file line number Diff line number Diff line change @@ -73,14 +73,15 @@ public IEnumerable<object> ColumnsAndFormulas
73
73
{
74
74
get
75
75
{
76
- if ( Items != null )
77
- return Items ;
78
- // Avoid a possible breaking change for mapping having left a column attribute along with a formula one.
79
- // This is a mapping error, but previous implementation was silently ignoring the column attribute in
80
- // such case.
81
- if ( ! string . IsNullOrEmpty ( formula ) )
82
- return AsFormulas ( ) ;
83
- return AsColumns ( ) ;
76
+ if ( Items != null && ( ! string . IsNullOrEmpty ( column ) || ! string . IsNullOrEmpty ( formula ) ) )
77
+ throw new MappingException (
78
+ $ "On a map-key: specifying columns or formulas with both attributes and sub-elements is " +
79
+ $ "invalid. Please use only sub-elements, or only one of them as attribute") ;
80
+ if ( ! string . IsNullOrEmpty ( column ) && ! string . IsNullOrEmpty ( formula ) )
81
+ throw new MappingException (
82
+ $ "On a map-key: specifying both column and formula attributes is invalid. Please specify " +
83
+ $ "only one of them, or use sub-elements") ;
84
+ return Items ?? AsColumns ( ) . Cast < object > ( ) . Concat ( AsFormulas ( ) . Cast < object > ( ) ) ;
84
85
}
85
86
}
86
87
}
Original file line number Diff line number Diff line change @@ -82,14 +82,16 @@ public IEnumerable<object> ColumnsAndFormulas
82
82
{
83
83
get
84
84
{
85
- if ( Items != null )
86
- return Items ;
87
- // Avoid a possible breaking change for mapping having left a column attribute along with a formula one.
88
- // This is a mapping error, but previous implementation was silently ignoring the column attribute in
89
- // such case.
90
- if ( ! string . IsNullOrEmpty ( formula ) )
91
- return AsFormulas ( ) ;
92
- return AsColumns ( ) ;
85
+ if ( Items != null && ( ! string . IsNullOrEmpty ( column ) || ! string . IsNullOrEmpty ( formula ) ) )
86
+ throw new MappingException (
87
+ $ "On a map-key-many-to-many targeting { EntityName } : specifying columns or formulas with both " +
88
+ $ "attributes and sub-elements is invalid. Please use only sub-elements, or only one of them " +
89
+ $ "as attribute") ;
90
+ if ( ! string . IsNullOrEmpty ( column ) && ! string . IsNullOrEmpty ( formula ) )
91
+ throw new MappingException (
92
+ $ "On a map-key-many-to-many targeting { EntityName } : specifying both column and formula " +
93
+ $ "attributes is invalid. Please specify only one of them, or use sub-elements") ;
94
+ return Items ?? AsColumns ( ) . Cast < object > ( ) . Concat ( AsFormulas ( ) . Cast < object > ( ) ) ;
93
95
}
94
96
}
95
97
}
Original file line number Diff line number Diff line change @@ -113,14 +113,15 @@ public IEnumerable<object> ColumnsAndFormulas
113
113
{
114
114
get
115
115
{
116
- if ( Items != null )
117
- return Items ;
118
- // Avoid a possible breaking change for mapping having left a column attribute along with a formula one.
119
- // This is a mapping error, but previous implementation was silently ignoring the column attribute in
120
- // such case.
121
- if ( ! string . IsNullOrEmpty ( formula ) )
122
- return AsFormulas ( ) ;
123
- return AsColumns ( ) ;
116
+ if ( Items != null && ( ! string . IsNullOrEmpty ( column ) || ! string . IsNullOrEmpty ( formula ) ) )
117
+ throw new MappingException (
118
+ $ "On { Name } property: specifying columns or formulas with both attributes and " +
119
+ $ "sub-elements is invalid. Please use only sub-elements, or only one of them as attribute") ;
120
+ if ( ! string . IsNullOrEmpty ( column ) && ! string . IsNullOrEmpty ( formula ) )
121
+ throw new MappingException (
122
+ $ "On { Name } property: specifying both column and formula attributes is invalid. Please " +
123
+ $ "specify only one of them, or use sub-elements") ;
124
+ return Items ?? AsColumns ( ) . Cast < object > ( ) . Concat ( AsFormulas ( ) . Cast < object > ( ) ) ;
124
125
}
125
126
}
126
127
}
You can’t perform that action at this time.
0 commit comments