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

Honor explicit index name #268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Honor explicit index name #268

wants to merge 1 commit into from

Conversation

serhiiz
Copy link

@serhiiz serhiiz commented Feb 17, 2024

When an index is created and an explicit name is provided, the name should not be rewritten. There is also a unit test to ensure that the explicit name for a foreign key is also honored.

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

  1. Foreign Key Constraint Name Testing:
    o Old Code: Did not include a test for verifying foreign key constraint names.
    o New Code: Includes a test (Foreign_key_with_explicit_constraint_name) to verify the explicit constraint name for a foreign key.
  2. Index Name Testing:
    o Old Code: Had a basic test for verifying index names (Index method).
    o New Code: Extends the index name testing with an additional test (Index_with_explicit_name) to verify the explicit index name.
  3. Tph Method:
    o Both the old and new snippets have an empty placeholder for the Tph method, indicating it is not implemented in the provided snippet.
    Improvements Needed
  4. Completing Tph Method:
    o Implement the Tph method in both old and new code snippets to complete the test suite.
  5. Consistency and Coverage:
    o Ensure that all essential aspects of entity configuration (like Table Per Hierarchy mappings) are adequately tested in the unit test suite.
  6. Documentation and Context:
    o Document the purpose and expected behavior of each test method to facilitate understanding and maintenance by other developers.
    Summary
    The updated code snippet introduces tests for verifying explicit names of foreign key constraints and indexes, enhancing coverage and specificity in the unit test suite. Ensure completeness by implementing the Tph method and maintaining consistency across all test methods.

[Fact]
public void Index()
{
var entityType = BuildEntityType(b => b.Entity<SampleEntity>().HasIndex(s => s.SomeProperty));
Assert.Equal("ix_sample_entity_some_property", entityType.GetIndexes().Single().GetDatabaseName());
}

[Fact]
public void Index_with_explicit_name()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test actually fail before this change? Conventions in EF can never override explicit user configuration anyway, so I'm not sure if the change below is actually needed… Can you please confirm?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test actually fail before this change? Conventions in EF can never override explicit user configuration anyway, so I'm not sure if the change below is actually needed… Can you please confirm?

Yes, this test was failing before the change.

Regarding the second test for a foreign key - this test was not failing and it's there to detect when things may get broken. When I was investigating it, that was working because of a defect in EF. I don't remember all the details, but the code, which is part of EF, was setting an annotation with explicit index name and not firing the event about annotation changed. So, if one day that defect is fixed, explicit index names will be overridden, and the test will show that.

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

Successfully merging this pull request may close these issues.

3 participants