@@ -31,32 +31,32 @@ public sealed class DefaultModelTypeBuilder : IModelTypeBuilder
3131 * incorrect bucket is picked, then the type mapping will fail. the model type builder detects if a model
3232 * is ad hoc. if it is, then it will recursively create a private instance of itself to handle the ad hoc
3333 * bucket. normal odata cannot opt out of this process because the explored type must match the edm. a type
34- * mapped via an ad hoc edm is not really odata so it can opt out if desired. the opt out process is more
35- * of a failsafe and optimization. if the ad hoc edm wasn't customized, then the meta model and type should
36- * be exactly the same, which will result in no substitution.
34+ * mapped via an ad hoc edm is not really odata so it should opt out by default because without an edm
35+ * there is not away to control member serialization/deserialization easily. such cases will typically
36+ * create a type-per-version, as is common for non-odata, which negates the need for model substitution.
37+ * a user can opt into ad hoc model substitution if they have a way to deal with member filtering.
3738 */
3839
3940 private static Type ? ienumerableOfT ;
4041 private readonly bool adHoc ;
42+ private readonly bool excludeAdHocModels ;
4143 private DefaultModelTypeBuilder ? adHocBuilder ;
4244 private ConcurrentDictionary < ApiVersion , ModuleBuilder > ? modules ;
4345 private ConcurrentDictionary < ApiVersion , IDictionary < EdmTypeKey , Type > > ? generatedEdmTypesPerVersion ;
4446 private ConcurrentDictionary < ApiVersion , ConcurrentDictionary < EdmTypeKey , Type > > ? generatedActionParamsPerVersion ;
4547
46- private DefaultModelTypeBuilder ( bool adHoc ) => this . adHoc = adHoc ;
48+ private DefaultModelTypeBuilder ( bool excludeAdHocModels , bool adHoc )
49+ {
50+ this . adHoc = adHoc ;
51+ this . excludeAdHocModels = excludeAdHocModels ;
52+ }
4753
4854 /// <summary>
4955 /// Initializes a new instance of the <see cref="DefaultModelTypeBuilder"/> class.
5056 /// </summary>
51- public DefaultModelTypeBuilder ( ) { }
52-
53- /// <summary>
54- /// Gets or sets a value indicating whether types from an ad hoc Entity Data Model
55- /// (EDM) should be excluded.
56- /// </summary>
57- /// <value>True if types from an ad hoc EDM are excluded; otherwise, false. The
58- /// default value is <c>false</c>.</value>
59- public bool ExcludeAdHocModels { get ; set ; }
57+ /// <param name="includeAdHocModels">Indicates whether types from an ad hoc Entity
58+ /// Data Model (EDM) should be included.</param>
59+ public DefaultModelTypeBuilder ( bool includeAdHocModels = false ) => excludeAdHocModels = ! includeAdHocModels ;
6060
6161 /// <inheritdoc />
6262 public Type NewStructuredType ( IEdmModel model , IEdmStructuredType structuredType , Type clrType , ApiVersion apiVersion )
@@ -68,13 +68,13 @@ public Type NewStructuredType( IEdmModel model, IEdmStructuredType structuredTyp
6868
6969 if ( model . IsAdHoc ( ) )
7070 {
71- if ( ExcludeAdHocModels )
71+ if ( excludeAdHocModels )
7272 {
7373 return clrType ;
7474 }
7575 else if ( ! adHoc )
7676 {
77- adHocBuilder ??= new ( adHoc : true ) ;
77+ adHocBuilder ??= new ( excludeAdHocModels , adHoc : true ) ;
7878 return adHocBuilder . NewStructuredType ( model , structuredType , clrType , apiVersion ) ;
7979 }
8080 }
@@ -111,7 +111,7 @@ public Type NewActionParameters( IEdmModel model, IEdmAction action, string cont
111111
112112 if ( ! adHoc && model . IsAdHoc ( ) )
113113 {
114- adHocBuilder ??= new ( adHoc : true ) ;
114+ adHocBuilder ??= new ( excludeAdHocModels , adHoc : true ) ;
115115 return adHocBuilder . NewActionParameters ( model , action , controllerName , apiVersion ) ;
116116 }
117117
0 commit comments