【问题标题】:Linq query not working in AWS with .Net Core and EF CoreLinq 查询无法在 AWS 中使用 .Net Core 和 EF Core
【发布时间】:2021-02-22 00:16:55
【问题描述】:

我正在使用 EF Core 开发 .NET Core 3.1 Web API,并且此 API 已部署到 AWS Lambda。下面代码中面临的问题是,它一直执行到控制台日志。然后在 api 返回以下带有状态码的消息后

504 网关超时:

"message": "端点请求超时"

CoreContext 扩展DbContext

public async Task<IList<ChannelsEnvelope>> GetChannels()
{
        using (var scope = _services.CreateScope())
        {
            Console.WriteLine("inside scope123");  // works till here.
            var _coreContext = scope.ServiceProvider.GetRequiredService<CoreContext>();

            var query = from a in _coreContext.DistributionChannels
                        where a.Active == true
                        orderby a.Channel ascending
                        select new ChannelsEnvelope
                        {
                            ID = a.Id,
                            Channel = a.Channel,
                            Description = a.Description
                        };

            return await query.AsNoTracking().ToListAsync();
        }
}

aws中的执行日志:

【问题讨论】:

    标签: c# amazon-web-services asp.net-core aws-lambda entity-framework-core


    【解决方案1】:

    GetRequiredService 方法是 .Net 平台扩展的一部分。详情请见Microsoft Docs

    一方面,.Net 平台扩展上有某些limitations,另一方面,AWS Lambda 在 Linux 平台上运行并使用可能不支持 .Net Core 运行时的所有功能的custom runtime

    请浏览以上链接并确认您的代码中使用的 API 是否在 AWS Lambda 上受支持。

    【讨论】:

    • 也试过用这个,但没用。使用 (var _coreContext = new CoreContext()) { Console.WriteLine("inside scope123");尝试 { var query = from a in _coreContext.DistributionChannels
    猜你喜欢
    • 2020-03-29
    • 2020-09-27
    • 2020-01-25
    • 1970-01-01
    • 2021-05-03
    • 2019-12-17
    • 1970-01-01
    • 2021-09-06
    • 2019-03-27
    相关资源
    最近更新 更多