无法从 Masstransit Saga 事件更新实体框架核心关系

问题描述 投票:0回答:1

我无法更新我的传奇实例事件中的实体关系。

我能够为条目创建一对一的行,但是当我再次回到 IssueLocation 状态时,它没有检测到行已存在并且出现错误

这是我的代码https://github.com/jaisopenoffice/IssueRequestStateMachine/tree/master

我需要更新 IssueLocation 而不是添加新记录(在 IssueTypeAccepted 事件中)。第一次它工作,但当我再次回到相同的状态时,它正在尝试创建新记录。有正确的方法吗?

entity-framework .net-core entity-framework-core masstransit automatonymous
1个回答
0
投票

显然你必须处理你的映射,但我知道这是一个老问题,但我很难找到答案。在我的 Program.cs 中,我添加了一个自定义 .include 语句。它完美地加载它,并完美地更新它(以前它仅在我 .saga.Person = .message.Person 时更新,并且仅在我转换到另一个状态时才持续存在)所以希望这对其他人有帮助。

x.AddSagaStateMachine<PersonStateMachine, PersonState>() 
.EntityFrameworkRepository(r =>
{
    r.ExistingDbContext<PersonSagaDbContext>();
    r.UseSqlServer();
    r.CustomizeQuery(query =>
    {
        return query.Include(s => s.Person);
    });
}); 
© www.soinside.com 2019 - 2024. All rights reserved.