@@ -3046,6 +3046,9 @@ public void Can_use_relational_model_with_SQL_queries()
3046
3046
private static IQueryable < Order > GetOrdersForCustomer ( int id )
3047
3047
=> throw new NotImplementedException ( ) ;
3048
3048
3049
+ private static IQueryable < Order > GetOrdersForCustomer ( string name )
3050
+ => throw new NotImplementedException ( ) ;
3051
+
3049
3052
[ ConditionalFact ]
3050
3053
public void Can_use_relational_model_with_functions ( )
3051
3054
{
@@ -3064,41 +3067,50 @@ public void Can_use_relational_model_with_functions()
3064
3067
3065
3068
modelBuilder . HasDbFunction (
3066
3069
typeof ( RelationalModelTest ) . GetMethod (
3067
- nameof ( GetOrdersForCustomer ) , BindingFlags . NonPublic | BindingFlags . Static ) ) ;
3070
+ nameof ( GetOrdersForCustomer ) , BindingFlags . NonPublic | BindingFlags . Static , [ typeof ( int ) ] ) ) ;
3071
+
3072
+ modelBuilder . HasDbFunction (
3073
+ typeof ( RelationalModelTest ) . GetMethod (
3074
+ nameof ( GetOrdersForCustomer ) , BindingFlags . NonPublic | BindingFlags . Static , [ typeof ( string ) ] ) ) ;
3068
3075
3069
3076
var model = Finalize ( modelBuilder ) ;
3070
3077
3071
3078
Assert . Single ( model . Model . GetEntityTypes ( ) ) ;
3072
- Assert . Equal ( 2 , model . Functions . Count ( ) ) ;
3079
+ Assert . Equal ( 3 , model . Functions . Count ( ) ) ;
3073
3080
Assert . Empty ( model . Views ) ;
3074
3081
Assert . Empty ( model . Tables ) ;
3075
3082
3076
3083
var orderType = model . Model . FindEntityType ( typeof ( Order ) ) ;
3077
3084
Assert . Null ( orderType . FindPrimaryKey ( ) ) ;
3078
3085
3079
- Assert . Equal ( 2 , orderType . GetFunctionMappings ( ) . Count ( ) ) ;
3086
+ Assert . Equal ( 3 , orderType . GetFunctionMappings ( ) . Count ( ) ) ;
3080
3087
var orderMapping = orderType . GetFunctionMappings ( ) . First ( ) ;
3081
3088
Assert . Null ( orderMapping . IsSharedTablePrincipal ) ;
3082
3089
Assert . Null ( orderMapping . IsSplitEntityTypePrincipal ) ;
3083
3090
Assert . True ( orderMapping . IsDefaultFunctionMapping ) ;
3084
3091
3085
- var tvfMapping = orderType . GetFunctionMappings ( ) . Last ( ) ;
3092
+ var tvfMapping = orderType . GetFunctionMappings ( ) . ElementAt ( 1 ) ;
3086
3093
Assert . Null ( tvfMapping . IsSharedTablePrincipal ) ;
3087
3094
Assert . Null ( tvfMapping . IsSplitEntityTypePrincipal ) ;
3088
3095
Assert . False ( tvfMapping . IsDefaultFunctionMapping ) ;
3089
3096
3097
+ var tvfMapping2 = orderType . GetFunctionMappings ( ) . Last ( ) ;
3098
+ Assert . Null ( tvfMapping2 . IsSharedTablePrincipal ) ;
3099
+ Assert . Null ( tvfMapping2 . IsSplitEntityTypePrincipal ) ;
3100
+ Assert . False ( tvfMapping2 . IsDefaultFunctionMapping ) ;
3101
+
3090
3102
Assert . Null ( orderMapping . IncludesDerivedTypes ) ;
3091
3103
Assert . Equal (
3092
- new [ ] { nameof ( Order . AlternateId ) , nameof ( Order . CustomerId ) , nameof ( Order . Id ) , nameof ( Order . OrderDate ) } ,
3104
+ [ nameof ( Order . AlternateId ) , nameof ( Order . CustomerId ) , nameof ( Order . Id ) , nameof ( Order . OrderDate ) ] ,
3093
3105
orderMapping . ColumnMappings . Select ( m => m . Property . Name ) ) ;
3094
3106
3095
3107
var ordersFunction = orderMapping . StoreFunction ;
3096
3108
Assert . Same ( ordersFunction , model . FindFunction ( ordersFunction . Name , ordersFunction . Schema , [ ] ) ) ;
3097
3109
Assert . Equal (
3098
- new [ ] { orderType } ,
3110
+ [ orderType ] ,
3099
3111
ordersFunction . EntityTypeMappings . Select ( m => m . TypeBase ) ) ;
3100
3112
Assert . Equal (
3101
- new [ ] { nameof ( Order . CustomerId ) , nameof ( Order . Id ) , nameof ( Order . OrderDate ) , "SomeName" } ,
3113
+ [ nameof ( Order . CustomerId ) , nameof ( Order . Id ) , nameof ( Order . OrderDate ) , "SomeName" ] ,
3102
3114
ordersFunction . Columns . Select ( m => m . Name ) ) ;
3103
3115
Assert . Equal ( "GetOrders" , ordersFunction . Name ) ;
3104
3116
Assert . Null ( ordersFunction . Schema ) ;
@@ -3117,7 +3129,7 @@ public void Can_use_relational_model_with_functions()
3117
3129
Assert . Same ( orderDateColumn , ordersFunction . FindColumn ( nameof ( Order . OrderDate ) ) ) ;
3118
3130
Assert . Same ( orderDateColumn , orderDate . FindColumn ( StoreObjectIdentifier . DbFunction ( ordersFunction . Name ) ) ) ;
3119
3131
Assert . Same ( orderDateColumn , ordersFunction . FindColumn ( orderDate ) ) ;
3120
- Assert . Equal ( new [ ] { orderDate } , orderDateColumn . PropertyMappings . Select ( m => m . Property ) ) ;
3132
+ Assert . Equal ( [ orderDate ] , orderDateColumn . PropertyMappings . Select ( m => m . Property ) ) ;
3121
3133
Assert . Equal ( nameof ( Order . OrderDate ) , orderDateColumn . Name ) ;
3122
3134
Assert . Equal ( "default_datetime_mapping" , orderDateColumn . StoreType ) ;
3123
3135
Assert . False ( orderDateColumn . IsNullable ) ;
@@ -3127,7 +3139,7 @@ public void Can_use_relational_model_with_functions()
3127
3139
3128
3140
var tvfFunction = tvfMapping . StoreFunction ;
3129
3141
Assert . Same ( tvfMapping , tvfFunction . EntityTypeMappings . Single ( ) ) ;
3130
- Assert . Same ( tvfFunction , model . FindFunction ( tvfFunction . Name , tvfFunction . Schema , new [ ] { "default_int_mapping" } ) ) ;
3142
+ Assert . Same ( tvfFunction , model . FindFunction ( tvfFunction . Name , tvfFunction . Schema , [ "default_int_mapping" ] ) ) ;
3131
3143
Assert . Equal ( nameof ( GetOrdersForCustomer ) , tvfFunction . Name ) ;
3132
3144
Assert . Null ( tvfFunction . Schema ) ;
3133
3145
Assert . False ( tvfFunction . IsBuiltIn ) ;
@@ -3136,9 +3148,24 @@ public void Can_use_relational_model_with_functions()
3136
3148
3137
3149
var tvfDbFunction = tvfFunction . DbFunctions . Single ( ) ;
3138
3150
Assert . Same ( tvfFunction , tvfDbFunction . StoreFunction ) ;
3139
- Assert . Same ( model . Model . GetDbFunctions ( ) . Single ( f => f . Parameters . Count ( ) == 1 ) , tvfDbFunction ) ;
3151
+ Assert . Same ( model . Model . GetDbFunctions ( ) . First ( f => f . Parameters . Count ( ) == 1 ) , tvfDbFunction ) ;
3140
3152
Assert . Same ( tvfFunction . Parameters . Single ( ) , tvfDbFunction . Parameters . Single ( ) . StoreFunctionParameter ) ;
3141
3153
Assert . Equal ( tvfDbFunction . Parameters . Single ( ) . Name , tvfFunction . Parameters . Single ( ) . DbFunctionParameters . Single ( ) . Name ) ;
3154
+
3155
+ var tvfFunction2 = tvfMapping2 . StoreFunction ;
3156
+ Assert . Same ( tvfMapping2 , tvfFunction2 . EntityTypeMappings . Single ( ) ) ;
3157
+ Assert . Same ( tvfFunction2 , model . FindFunction ( tvfFunction2 . Name , tvfFunction2 . Schema , [ "just_string(max)" ] ) ) ;
3158
+ Assert . Equal ( nameof ( GetOrdersForCustomer ) , tvfFunction2 . Name ) ;
3159
+ Assert . Null ( tvfFunction2 . Schema ) ;
3160
+ Assert . False ( tvfFunction2 . IsBuiltIn ) ;
3161
+ Assert . False ( tvfFunction2 . IsShared ) ;
3162
+ Assert . Null ( tvfFunction2 . ReturnType ) ;
3163
+
3164
+ var tvfDbFunction2 = tvfFunction2 . DbFunctions . Single ( ) ;
3165
+ Assert . Same ( tvfFunction2 , tvfDbFunction2 . StoreFunction ) ;
3166
+ Assert . Same ( model . Model . GetDbFunctions ( ) . Last ( f => f . Parameters . Count ( ) == 1 ) , tvfDbFunction2 ) ;
3167
+ Assert . Same ( tvfFunction2 . Parameters . Single ( ) , tvfDbFunction2 . Parameters . Single ( ) . StoreFunctionParameter ) ;
3168
+ Assert . Equal ( tvfDbFunction2 . Parameters . Single ( ) . Name , tvfFunction2 . Parameters . Single ( ) . DbFunctionParameters . Single ( ) . Name ) ;
3142
3169
}
3143
3170
3144
3171
[ ConditionalFact ]
0 commit comments