@@ -101,34 +101,23 @@ protected virtual void ValidateVectorColumns(
101101 IModel model ,
102102 IDiagnosticsLogger < DbLoggerCategory . Model . Validation > logger )
103103 {
104- foreach ( var entityType in model . GetEntityTypes ( ) )
105- {
106- ValidateVectorColumns ( entityType ) ;
107- }
108-
109- void ValidateVectorColumns ( ITypeBase typeBase )
104+ foreach ( var property in model . GetEntityTypes ( ) . SelectMany ( t => t . GetFlattenedDeclaredProperties ( ) ) )
110105 {
111- foreach ( var property in typeBase . GetDeclaredProperties ( ) )
106+ if ( property . FindTypeMapping ( ) is not SqlServerVectorTypeMapping vectorTypeMapping )
112107 {
113- if ( property . GetTypeMapping ( ) is SqlServerVectorTypeMapping vectorTypeMapping )
114- {
115- if ( property . DeclaringType . IsMappedToJson ( ) )
116- {
117- throw new InvalidOperationException (
118- SqlServerStrings . VectorPropertiesNotSupportedInJson ( property . DeclaringType . DisplayName ( ) , property . Name ) ) ;
119- }
108+ continue ;
109+ }
120110
121- if ( vectorTypeMapping . Size is null )
122- {
123- throw new InvalidOperationException (
124- SqlServerStrings . VectorDimensionsMissing ( property . DeclaringType . DisplayName ( ) , property . Name ) ) ;
125- }
126- }
111+ if ( property . DeclaringType . IsMappedToJson ( ) )
112+ {
113+ throw new InvalidOperationException (
114+ SqlServerStrings . VectorPropertiesNotSupportedInJson ( property . DeclaringType . DisplayName ( ) , property . Name ) ) ;
127115 }
128116
129- foreach ( var complexProperty in typeBase . GetDeclaredComplexProperties ( ) )
117+ if ( vectorTypeMapping . Size is null )
130118 {
131- ValidateVectorColumns ( complexProperty . ComplexType ) ;
119+ throw new InvalidOperationException (
120+ SqlServerStrings . VectorDimensionsMissing ( property . DeclaringType . DisplayName ( ) , property . Name ) ) ;
132121 }
133122 }
134123 }
@@ -191,20 +180,18 @@ protected override void ValidateTypeMappings(
191180 var strategy = property . GetValueGenerationStrategy ( ) ;
192181 var propertyType = property . ClrType ;
193182
194- if ( strategy == SqlServerValueGenerationStrategy . IdentityColumn
195- && ! SqlServerPropertyExtensions . IsCompatibleWithValueGeneration ( property ) )
196- {
197- throw new InvalidOperationException (
198- SqlServerStrings . IdentityBadType (
199- property . Name , property . DeclaringType . DisplayName ( ) , propertyType . ShortDisplayName ( ) ) ) ;
200- }
201-
202- if ( strategy is SqlServerValueGenerationStrategy . SequenceHiLo or SqlServerValueGenerationStrategy . Sequence
203- && ! SqlServerPropertyExtensions . IsCompatibleWithValueGeneration ( property ) )
183+ switch ( property . GetValueGenerationStrategy ( ) )
204184 {
205- throw new InvalidOperationException (
206- SqlServerStrings . SequenceBadType (
207- property . Name , property . DeclaringType . DisplayName ( ) , propertyType . ShortDisplayName ( ) ) ) ;
185+ case SqlServerValueGenerationStrategy . IdentityColumn
186+ when ! SqlServerPropertyExtensions . IsCompatibleWithValueGeneration ( property ) :
187+ throw new InvalidOperationException (
188+ SqlServerStrings . IdentityBadType (
189+ property . Name , property . DeclaringType . DisplayName ( ) , propertyType . ShortDisplayName ( ) ) ) ;
190+ case SqlServerValueGenerationStrategy . SequenceHiLo or SqlServerValueGenerationStrategy . Sequence
191+ when ! SqlServerPropertyExtensions . IsCompatibleWithValueGeneration ( property ) :
192+ throw new InvalidOperationException (
193+ SqlServerStrings . SequenceBadType (
194+ property . Name , property . DeclaringType . DisplayName ( ) , propertyType . ShortDisplayName ( ) ) ) ;
208195 }
209196 }
210197 }
0 commit comments