[英]In-memory database filtering by null value not working
I've got a working piece of code, that I want to cover with unit tests.我有一段工作代码,我想用单元测试来介绍。 However Microsoft's in-memory database returns some unexpected values.然而,微软的内存数据库返回了一些意想不到的值。
If I query like that如果我这样查询
var count = query.Count(c => c.Birthday2000 != null);
the result is 0, although it should be 12.结果是 0,尽管它应该是 12。
If I query that way如果我这样查询
var count = query.ToList().Count(c => c.Birthday2000 != null);
the result is 12, which was expected.结果是 12,这是预期的。
If I run it with my relational database (mysql) the first line works too.如果我用我的关系数据库(mysql)运行它,第一行也可以。
I've got the following model我有以下 model
public class Customer
{
public DateTime? BirthDay {get; set; }
private DateTime? _birthday2000;
public DateTime? BirthDay2000
{
get
{
if (BirthDay == null) _birthday2000 = null;
else _birthday2000 = new DateTime(2000, BirthDay.Value.Month, BirthDay.Value.Day);
return _birthday2000;
}
set => _birthday2000 = value;
}
}
What could cause that issue?什么可能导致该问题?
My goal is to query the database for the next n birthdays to come.我的目标是查询数据库中接下来的 n 个生日。 I can't order and filter BirthDay, because the year-portion differs, that's why I introduced a BirthDay2000-property where the year gets set to a fixes year.我无法订购和过滤 BirthDay,因为年份部分不同,这就是为什么我引入了 BirthDay2000 属性,其中年份设置为修复年份。
I used a custom g/setter to set it automatically when I receive new customers by a webservice.当我通过网络服务接收新客户时,我使用自定义 g/setter 自动设置它。
Not only is your BirthDay2000
invalid as far as mapping EF.Core to a database of any kind (ORMs use data objects, not logic objects), it's fairly invalid as far as properties go in general as well: your getter has side effects.就将 EF.Core 映射到任何类型的数据库(ORM 使用数据对象,而不是逻辑对象)而言,您的BirthDay2000
不仅无效,而且就属性 go 而言,它也相当无效:您的吸气剂有副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.