Azure Functions return IQueryable

Piotr Stulinski

I would like to build an API on Azure Functions but need to use Iqueryable with entityframework.

Is it possible to return an IQueryable from an azure function?

Bowman Zhu

Yes, you can.

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;

namespace FunctionApp12
{
    public static class Function1
    {
        private static SortedDictionary<string, string> _dataValue;

        [FunctionName("Function1")]
        public static IQueryable<object> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            _dataValue = new SortedDictionary<string, string>();
            _dataValue.Add("test1", "This is test1.");
            IQueryable<object> query = _dataValue.AsQueryable().Select(r => r.Value);
            log.LogInformation("This is a test.");
            return query;
        }
    }
}

Hit the endpoint, you will get:

enter image description here

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事