首页 > 解决方案 > SQLKata 简单 SELECT 查询返回合法表的“无效对象名称”?

问题描述

有没有人使用过 SqlKata 库并且在做一个简单的 SELECT * FROM TABLE 时遇到问题?我已经尝试了标准 GET(它产生一个在 [] 中包含表的查询,以及产生没有 [] 的查询的 GetRaw)。

对于一个清晰可用的表,两个查询都返回无效的对象名称?我的应用程序在日志中记录以下内容:

[Error] SELECT * FROM InSiteStoreInfo
[Error] Invalid object name 'InSiteStoreInfo'.

我正在使用的示例代码如下(我也尝试过 Get 的非原始版本)。

public async Task<APIGatewayProxyResponse> GetQueryKata(APIGatewayProxyRequest request, ILambdaContext context)
    {
        LogLevel environmentLogLevel = (LogLevel)Convert.ToInt32(Environment.GetEnvironmentVariable("LOG_LEVEL"));
        string jsonOutput = null;
        APIGatewayProxyResponse proxyResponse = new APIGatewayProxyResponse(); 

        try
        {
            using (var connection = new SqlConnection(
                await RetrieveParameterStoreValue(ParameterStoreStrings.Database, true, context, environmentLogLevel)))
            {

                var db = new QueryFactory(connection, new SqlServerCompiler());

                // Log the compiled query to the console
                db.Logger = compiled => {
                   CreateCloudWatchLog(compiled.ToString(),context,LogLevel.Error,environmentLogLevel);
                };

                var results = db.Query().FromRaw("InSiteStoreInfo").Get();
                CreateCloudWatchLog(JsonConvert.SerializeObject(results, Formatting.Indented),context, LogLevel.Error,environmentLogLevel);
                jsonOutput = JsonConvert.SerializeObject(results, Formatting.Indented);
            }

            proxyResponse = await BuildResponse(jsonOutput, HttpStatusCode.OK, context, environmentLogLevel);
        }
        catch (Exception ex)
        {
            CreateCloudWatchLog(ex.Message, context, LogLevel.Error, environmentLogLevel);
            proxyResponse = await BuildResponse(ex.Message, HttpStatusCode.BadRequest, context, environmentLogLevel);
        }

        return proxyResponse; 
    }

标签: c#sql.netsqlkata

解决方案


推荐阅读