/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public DbFunction( [NotNull] MethodInfo methodInfo, [NotNull] IMutableModel model, ConfigurationSource configurationSource) { if (methodInfo.IsGenericMethod) { throw new ArgumentException(RelationalStrings.DbFunctionGenericMethodNotSupported(methodInfo.DisplayName())); } if (!methodInfo.IsStatic && !typeof(DbContext).IsAssignableFrom(methodInfo.DeclaringType)) { // ReSharper disable once AssignNullToNotNullAttribute throw new ArgumentException( RelationalStrings.DbFunctionInvalidInstanceType( methodInfo.DisplayName(), methodInfo.DeclaringType.ShortDisplayName())); } if (methodInfo.ReturnType == null || methodInfo.ReturnType == typeof(void)) { throw new ArgumentException( RelationalStrings.DbFunctionInvalidReturnType( methodInfo.DisplayName(), methodInfo.ReturnType.ShortDisplayName())); } if (methodInfo.ReturnType.IsGenericType && methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(IQueryable <>)) { IsIQueryable = true; //todo - if the generic argument is not usuable as an entitytype should we throw here? IE IQueryable<int> //the built in entitytype will throw is the type is not a class if (model.FindEntityType(methodInfo.ReturnType.GetGenericArguments()[0]) == null) { model.AddEntityType(methodInfo.ReturnType.GetGenericArguments()[0]).SetAnnotation(RelationalAnnotationNames.QueryableFunctionResultType, null); } } MethodInfo = methodInfo; var parameters = methodInfo.GetParameters(); _parameters = parameters .Select((pi, i) => new DbFunctionParameter(this, pi.Name, pi.ParameterType)) .ToList(); ModelName = GetFunctionName(methodInfo, parameters); _model = model; _configurationSource = configurationSource; Builder = new DbFunctionBuilder(this); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public DbFunction( [NotNull] string name, [NotNull] IMutableModel model, ConfigurationSource configurationSource) { ModelName = name; _parameters = new List <DbFunctionParameter>(); _model = model; _configurationSource = configurationSource; Builder = new DbFunctionBuilder(this); }