在我的应用程序中,我遵循DDD原则,因此我有一些ValueObject
像页脚设置
public class FooterSettings : ValueObjectBase<FooterSettings>
{
public bool ShowAddress { get; private set; }
public bool ShowPageCount { get; private set; }
public bool ShowAppVersion { get; private set; }
private FooterSettings() { }
public FooterSettings (bool showAddress, bool showPageCount, bool showAppVersion)
{
this.ShowAddress = showAddress;
this.ShowPageCount = showPageCount;
this.ShowAppVersion = showAppVersion ;
}
}
和我的DBcontext模型创建映射
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Domain.Page>()
.OwnsOne(x => x.FooterSettings);
}
现在,每当我更改FooterSettings
并尝试将新值对象设置为Page.FooterSettings
时,我都会收到以下异常
The instance of entity type 'Page.FooterSettings#FooterSettings' cannot be tracked because another instance with the key value 'PageId:8' is already being tracked. When replacing owned entities modify the properties without changing the instance or detach the previous owned entity entry first.