c# - 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;
}
解决方案
推荐阅读
- java - 如何在 Lagom 中提供静态资产?
- excel - Excel 根据列表结果的长度展开公式
- arrays - 使用按引用调用(函数和指针)查找数组中的最大元素
- javascript - 如何在 Javascript 中创建 2darray tilemap 的边界?
- python - 有没有办法在不明确输入每个字段名称的情况下进行 Group By 和 Sum?
- python - Win 10 未从 Python 代码中检测到鼠标移动
- git - git remote - 如何更改引用
- flutter - Flutter Charts - 标记颜色与系列颜色不匹配
- c# - 为什么锁需要 C# 中的实例?
- nginx - 在 NGINX 中只允许本地网络访问子域