Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF核心跟踪不可变值对象_C#_Domain Driven Design_Ddd Repositories_Ef Core 2.0 - Fatal编程技术网

C# EF核心跟踪不可变值对象

C# EF核心跟踪不可变值对象,c#,domain-driven-design,ddd-repositories,ef-core-2.0,C#,Domain Driven Design,Ddd Repositories,Ef Core 2.0,在我的应用程序中,我遵循DDD原则,因此我有一些ValueObject,比如页脚设置 public class FooterSettings : ValueObjectBase<FooterSettings> { public bool ShowAddress { get; private set; } public bool ShowPageCount { get; private set; } public bool ShowAppVersion { ge

在我的应用程序中,我遵循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 ;
    }
}
公共类页脚设置:ValueObjectBase
{
公共bool ShowAddress{get;private set;}
公共bool ShowPageCount{get;private set;}
公共bool ShowAppVersion{get;private set;}
私有页脚设置(){}
公共页脚设置(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); 
}
模型创建时受保护的覆盖无效(ModelBuilder ModelBuilder)
{
modelBuilder.Entity()
.OwnsOne(x=>x.FooterSettings);
}
现在,每次我更改
FooterSettings
并尝试将新值对象设置到
页面时,FooterSettings
都会出现以下异常

无法跟踪实体类型“Page.FooterSettings#FooterSettings”的实例,因为已跟踪键值为“PageId:8”的另一个实例。替换所属实体时,在不更改实例的情况下修改属性,或先分离以前的所属实体条目。

与标记为重复的相同问题。根据里程碑,您可以期望它在下一个EFC2.1.0中工作—您应该等待或打破原则(使用可变对象)