Dapper QuerySingleOrDefault不返回null

时间:2018-11-20 08:44:43

标签: c# dapper

为什么Dapper QuerySingleOrDefault不返回null? 我用苦干。 结果,我有带有默认字段的对象。 我在DB Browser中为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;
        }
    }

1 个答案:

答案 0 :(得分:1)

Sensorstruct。我将其更改为class 现在可以使用