【问题标题】:MongoDB Unknown discriminator valueMongoDB 未知鉴别器值
【发布时间】:2020-10-27 18:20:18
【问题描述】:

我已在此问题的答案中添加了代码:Unknown discriminator value 'MyEvent',但没有帮助。

反序列化 EventStore.EventMessage 类的 Body 属性时出错:未知鉴别器值:“插入事件名称”。 仅当您在程序重新启动后尝试重新水化已保存的对象时才会发生错误。

运行最新的 MyGet 构建

示例存储库:https://github.com/tonyeung/EventStore-MongoDB

复制问题:

运行程序
按 c 创建新记录
按q退出
再次运行程序
但按 r 补充水分
错误触发

如果运行程序,按 c,按 enter 继续,按 r 重新水化而不退出,对象重新水化没有问题。什么?

        using (var eventStore = WireupEventStore())
        {
            var snapshot = eventStore.Advanced.GetSnapshot(ID, int.MaxValue);
            if (snapshot == null)
            {
                // ERRORS HERE
                using (var stream = eventStore.OpenStream(ID, 0, int.MaxValue))
                {
                    var events = from s in stream.CommittedEvents
                                 select s.Body as IEvent;

                    obj.LoadsFromHistory(events);
                }
            }
        }

github问题:https://github.com/NEventStore/NEventStore/issues/203

【问题讨论】:

    标签: mongodb mongodb-.net-driver neventstore


    【解决方案1】:

    我想通了,因为我使用界面作为我的事件的标记,所以我不得不从 SO 问题中更改查询

            var types = Assembly.GetAssembly(typeof(SimpleCQRS.Event))
                    .GetTypes()
                    .Where(type => type.IsSubclassOf(typeof(SimpleCQRS.Event)));
    

            var type = typeof(IEvent);
            var types = Assembly.GetAssembly(typeof(IEvent))
                    .GetTypes()
                    .Where(t => type.IsAssignableFrom(t))
                    .Where(t => t.IsClass);
    

    【讨论】:

      猜你喜欢
      • 2011-11-19
      • 1970-01-01
      • 2022-01-16
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      相关资源
      最近更新 更多