Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting warning with Multilingual navigation. #6474

Closed
Ilkhom-S opened this issue Jun 16, 2022 · 9 comments
Closed

Getting warning with Multilingual navigation. #6474

Ilkhom-S opened this issue Jun 16, 2022 · 9 comments
Assignees
Milestone

Comments

@Ilkhom-S
Copy link

When I set

Product and ProductTranslation. EF Core showing this warning.

Entity 'Product' has a global query filter defined and is the required end of a relationship with the entity 'ProductTranslation'. This may lead to unexpected results when the required entity is filtered out. Either configure the navigation as optional, or define matching query filters for both entities in the navigation. See https://go.microsoft.com/fwlink/?linkid=2131316 for more information.

What is the good solution for this warning,

Should I mark entity navigation as optional or leave as it is ?

@ismcagdas
Copy link
Member

Are Product and ProductTranslation both multi tenant ?

@Ilkhom-S
Copy link
Author

Project is multitenant, but this entities not. I think it will give same warning for Multitenant Entity.
I think problems relies on Entity itself. I figured out when you declare class Entity<TPrimaryKey> EF Core adding indexes for navigation. But when I declare any class with Entity without specifying TPrimary key assuming that primary key int. EF core doesn't understand that binding.

@Ilkhom-S
Copy link
Author

For example:
when I declare entity such way,
class Product:CreationAuditedEntity without specifying TPrimary key. EF doesn't add any indexes

But when I declare class Product:CreationAuditedEntity<int, User> . EF see all relationship with 1-1 and add indexes for CreatedUser and DeletedUser .

I think entity with default int key should be avoided or documented. Because it can lead performance problem without indexes.

@Ilkhom-S
Copy link
Author

If problem with #6473 resolved, I think this warning should go away, because we can declare primary key explicitly

@ismcagdas ismcagdas added this to the v8.0 milestone Jun 20, 2022
@ismcagdas
Copy link
Member

We can check it after implementation of #6473

@sajasbana
Copy link

I notice there is another warning like below similar to this issue hope you can check it also, it show in fresh db migration
image

@ismcagdas
Copy link
Member

See #6255

@ismcagdas ismcagdas modified the milestones: v8.0, v8.1 Dec 8, 2022
@ismcagdas ismcagdas self-assigned this Jan 9, 2023
@Ilkhom-S
Copy link
Author

After entity explicitly defined, problem still exist. Still getting this warning.

@Ilkhom-S
Copy link
Author

Ilkhom-S commented Jan 24, 2023

I'm closing issue. In documentation there is no mentioned to put foreign key attribute. If you put on translations entity. Warning will go. Also , When updating with explicit set foreign key, you don't have to clear on context. EF automatically manages it.

Pasting my code if someone needs it .

public class ProductTranslation : Entity, IEntityTranslation<Product>
{
    public string Name { get; set; }
    [ForeignKey("CoreId")]  // This attribute should be set on translation entity
    public Product Core { get; set; }

    public int CoreId { get; set; }

    public string Language { get; set; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants