gpt4 book ai didi

c# - Dapper QuerySingleOrDefault 不返回 null

转载 作者:行者123 更新时间:2023-12-04 17:43:21 25 4
gpt4 key购买 nike

为什么 Dapper QuerySingleOrDefault 不返回 null?我用硬qwery。结果我有带有默认字段的对象。我在 DB Browser for SQLite 中运行了这个查询,它返回了 0 行。

public static Sensor GetSensor(string ip, string sensorName)
{
string sql = @"SELECT ip, name, invert, enable FROM DeviceAndOids AS A JOIN
DeviceForMonitoring AS B ON A.deviceForMonitoringKey=B.key JOIN
DeviceTypes AS C ON B.deviceTypeId=C.id WHERE
oidForDeviceKey IN (SELECT key FROM OidsForDevice WHERE
deviceTypeId IN (SELECT deviceTypeId FROM DeviceForMonitoring WHERE
ip = @ip) AND
name = @sensorName)";

using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var result = cnn.QuerySingleOrDefault<Sensor>(sql, new { ip, sensorName });
return result;
}
}

最佳答案

Sensorstruct 。我把它改成了 class现在可以用了

关于c# - Dapper QuerySingleOrDefault 不返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53389172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com