Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!