Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

363
Visualizações
What is the equivalent of entityEntry.Metadata.DefiningNavigationName() in EF Core 6?

I am using EF Core 5 and I have the following in my DBContext SaveChanges():

            if (entityEntry.Metadata.Name == "ArticleBankAggregate.ArticleTag" && entityEntry.Metadata.DefiningNavigationName != "Tags")
            {
                entityEntry.Property("UpdatedDate").CurrentValue = DateTime.Now;

                if (entityEntry.State == EntityState.Added)

                {
                    entityEntry.Property("CreatedDate").CurrentValue = DateTime.Now;
                }
            }

To update a shadow property.

I am trying to upgrade to EF Core 6 and I get the following:

CS0618: 'IReadOnlyEntityType.DefiningNavigationName' is obsolete: 'Entity types with defining navigations have been replaced by shared-type entity types'

I cant find any examples or understand how to change this to use shared-type entities.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Shared entity types are entity types which use common CLR type (class), and are identified by the entity type name (since the type is not enough).

Owned entity types now are implemented as shared types. The name of owned entity type consists of the name of the owner type + navigation property + type name. e.g. something like {Namespace}.{OwnerType}.{Navigation}#{OwnedType}.

So one way to adjust the above code is check the name of the entity in interest and just test directly for it. Another way closer to what are you doing before is to check the CLR type and in case it is owned, the navigation property name from owner to owned (the equivalent of the "defining navigation name"), which can be obtained with FindOwnership().PrincipalToDependent.Name, e.g. something like

if (entityEntry.Metadata.ClrType == typeof(ArticleTag)
    && entityEntry.Metadata.FindOwnership()?.PrincipalToDependent?.Name != "Tags")
 
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda