EFCore:无法将数据库类型tstzrange强制转换为NpgsqlRange`1

时间:2019-03-22 08:26:30

标签: c# npgsql entity-framework-core-2.2

我有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

0 个答案:

没有答案