通过 dapper [contrib] 在具有默认值的可空 bool 上检索 null 时出现问题

Problem retreiving null on nullable bool with default value through dapper [contrib]

这可能有点极端,也许我对默认值在这种情况下的工作方式的理解有误。

我有一个问题,下面的 属性 总是返回为 true,即使它在数据库中是 null。我想这是由于默认值造成的,但默认值不应该覆盖数据库中的内容——我是这么认为的。

部分模型..

public bool? SolvedByCalldesk { get; set; } = true;

Dapper.Contrib-call 的一部分..

...
var returnTask = connection.GetAsync<T>(id);
//caching here
result = await returnTask;
...

我已验证有问题的 DB 记录是 null,但 "result" returns 它是 true。这是我的问题吗,dapper 还是它如何处理可空类型的默认值?

我在 Dappers github 收到了对此问题的回复:

It is indeed behaving as intended. You can use a constructor approach instead if you want to override the behavior (just have a constructor that matches the columns you're pulling back) if you want complete control here :)

所以数据库中的任何 null 都将使用模型中的默认值,而不是数据库值(即使记录存在且 null 是 property/field).

的有效值

这样处理是有道理的,但同时也不完全正确i.m.o。