首页 > 解决方案 > Asp Net Core - 错误持久值对象

问题描述

我正在尝试从地址中保留一个值 valueobject,但出现以下错误,我正在使用 postgres,并且我已经尝试以多种方式映射此类,我看到有些人有类似的问题,但我没有找到解决方案。我只在使用 ef core 时遇到这个错误

System.InvalidOperationException:''EmpresaModel' 类型的实体正在与'EnderecoEmpresa' 类型的实体共享表'Empresa.Empresa',但没有具有相同键值的此类型实体已标记为'已添加' . 考虑使用“DbContextOptionsBuilder.EnableSensitiveDataLogging”来查看键值。

        builder.OwnsOne(e => e.EnderecoEmpresa, a =>
        {
            a.Property(p => p.Bairro).HasMaxLength(50)
                .HasColumnName("Bairro")
                .HasDefaultValue("");
            a.Property(p => p.CEP).HasMaxLength(10)
                .HasColumnName("CEP")
                .HasDefaultValue("");
            a.Property(p => p.Complemento).HasMaxLength(60)
                .HasColumnName("Complemento")
                .HasDefaultValue("");
            a.Property(p => p.IdMunicipio)
                .HasColumnName("MunicipioId");
            a.Property(p => p.IdUF)
                .HasColumnName("UfId");            
            a.Property(p => p.Logradouro)
                .HasColumnName("Logradouro").HasMaxLength(60)
                .HasDefaultValue("");
            a.Property(p => p.Numero)
                .HasColumnName("Numero").HasMaxLength(10)
                .HasDefaultValue("");
        });

标签: asp.net-core

解决方案


推荐阅读