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
HasIndex does not work as expected #10135
Comments
@denis-pujdak-adm-it - Indexes can be defined on scalar properties only which would be mapped to a database column. You are trying to use HasIndex with a navigation property which is invalid and would throw exception as above. If your intention is to define an index on the foreignkey property used by the relationship then you need to call HasIndex on ForeignKey property and not the navigation. You can configure foreignkey using b.HasOne(x => x.AppUser)
.WithMany()
.HasForeignKey("AppUserId") // Creates a column in database as AppUserId to store the FK value
.IsRequired();
b.HasIndex("AppUserId")
.HasName("IX_eo_MyTable_AppUser"); |
Thanks @smitpatel it's working. Cheers. |
Triage: we should throw a better message that doesn't reference "Property" since the app didn't call "Property" in this case. |
Update transient error message Add sensitive data to the conceptual null exception Don't validate mapping for shadow properties created by convention Improve incompatible principal entity during fixup exception Correct property is already a navigation exception Fixes #8363 Fixes #8365 Fixes #9696 Fixes #9817 Fixes #10135 Fixes #10856
Update transient error message Add sensitive data to the conceptual null exception Don't validate mapping for shadow properties created by convention Improve incompatible principal entity during fixup exception Correct property is already a navigation exception Fixes #8363 Fixes #8365 Fixes #9696 Fixes #9817 Fixes #10135 Fixes #10856
Update transient error message Add sensitive data to the conceptual null exception Don't validate mapping for shadow properties created by convention Improve incompatible principal entity during fixup exception Correct property is already a navigation exception Fixes #8363 Fixes #8365 Fixes #9696 Fixes #9817 Fixes #10135 Fixes #10856
I'm trying to map something like that:
MyTable class:
When I run the app I receive the following error:
One or more errors occurred. (Cannot call Property for the property 'AppUser' on entity type 'MyTable' because it is configured as a navigation property. Property can only be used to configure scalar properties.)
It is fine when I remove the code:
Could please someone help me? Thanks.
Further technical details
EF Core version: 2.0.0
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL 2.0.0
Operating system: Windows 10 Pro x64 (1703)
IDE: Visual Studio Community 2017
The text was updated successfully, but these errors were encountered: