ToMany 关系在 link() 处给出类型错误

ToMany relation gives type error at link()

我有 table:

    @Entity()
    @JsonSerializable()
    class DateTimeStruct {
      @JsonKey(ignore: true)
      int id = 0;
      DateTime time = DateTime.now();
      String? title;
    
      DateTimeStruct();
      factory DateTimeStruct.fromJson(Map<String, dynamic> json) => _$DateTimeStructFromJson(json);
      Map<String, dynamic> toJson() => _$DateTimeStructToJson(this);
    }

    @JsonSerializable(explicitToJson: true)
    @Entity()
    class Event {
      final Time = ToMany<DateTimeStruct>();
    }

当我尝试用 link 查询相关的 table 时,像这样:

    Store.box<Event>().query().link(Event_.Time,
          DateTimeStruct_.time.greaterOrEqual(DateTime.now().millisecondsSinceEpoch));

我明白了

The argument type 'QueryRelationMany<Event, DateTimeStruct>' can't be assigned to the parameter type 'QueryRelationProperty<Event, DateTimeStruct>'

错误信息。

第二个问题:DateTimeStruct_.time 解决为 QueryIntegerProperty<DateTimeStruct> time,但它是 DateTime。是否已在数据库中转换为整数?

  1. 给定实体无法与 pub run build_runner build 一起使用,因为 Event 缺少 id
  2. 您正在使用 ToMany 关系 - 如果您想为每个 Event 存储多个 DateTimeStruct,您只会想要这样做 - 只是确保您知道.如果每个事件只有一次很好(从概念上讲,这对我来说是正确的),请使用 ToOne.
  3. 使用 ToMany,您需要 link 使用 .linkMany() 而不是 .link() - 这就是编译错误的来源。
  4. 是 Dart DateTime 对象存储为毫秒时间戳(除非您使用 @Property(type: PropertyType.dateNano) annotation 另行指定)。您需要这样查询它们 - 您似乎做得对。