我有DbContext配置,例如
protected override void OnConfiguring(DbContextOptionsBuilder b)
{
if (b.IsConfigured)
return; // Breakpoint not reached, sure.
b.UseNpgsql(GetDefaultConnectionString(), opts =>
{
opts.MapRange<DateTimeOffset>("tstzrange");
});
}
示例类:
public class BlockedUser
{
// ...
public NpgsqlRange<DateTimeOffset> BlockedPeriod { get; set; }
}
它允许我在创建BlockedUser
表(包括tstzrange属性)的情况下应用数据库迁移,但是当我尝试从该表中获取数据时,NpgsqlDefaultDataReader.cs
引发以下异常:InvalidCastException: Can't cast database type tstzrange to NpgsqlRange`1
var user = await _dbContext.BlockedUsers
.FirstOrDefaultAsync(x => x.UserId == userId
&& x.BlockedPeriod.Contains(pointDate));
怎么了?
其他信息:Convert Infinity DateTime=True