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

EFCore CompareEfSql errors when schema has incorrect case #19

Closed
acblksun opened this issue May 20, 2019 · 6 comments
Closed

EFCore CompareEfSql errors when schema has incorrect case #19

acblksun opened this issue May 20, 2019 · 6 comments

Comments

@acblksun
Copy link

Hi,

We're finishing up a migration from EF6 to EF Core, and using CompareEfSql to validate the upgraded builder (especially the corner cases), and it's been a great tool to assist with this.

However we're having a small issue where the real schema was initially created all lowercase version, but the schema has since been changed to be pascal case. Further, either EF6 pascal cased the foreign key names, or perhaps another developer manually ignored the change when the schema was changed to pascal case.

The result is a mix of schema.Table and FK_Schema_ColumnId that is perfectly legal for Sql Server, and EF Core. The updated configuration works without errors.

public void Configure(EntityTypeBuilder<Terminal> builder)
{
    builder.ToTable(table: "Terminal", schema: "Store");

I realize we can just ignore these errors individually, but as with #9 it would be great to add a case-insensitive option when comparing schema (and/or table).

NOT IN DATABASE: Entity 'Terminal', table name. Expected = Store.Terminal

but once ignored, we then get the reverse error

EXTRA IN DATABASE: YourDatabaseName->Table 'store.Terminal'`

We would like it if the following does not fail

CREATE TABLE [purchase].[Order] ....

public void Configure(EntityTypeBuilder<Order> builder)
{
    builder.ToTable(table: "Order", schema: "Purchase"); // originally purchase
}

[Test]
public void ShouldMatchSchema()
{
    using (var context = new MyDbContext())
    {
        var config = new CompareEfSqlConfig();

        config.SchemaIgnoreCase = true;


        var comparer = new CompareEfSql(config);

        //ATTEMPT
        //This will compare EF Core model of the database 
        //with the database that the context's connection points to
        var hasErrors = comparer.CompareEfWithDb(context);

        //VERIFY
        //The CompareEfWithDb method returns true if there were errors.
        //The comparer.GetAllErrors property returns a string
        //where each error is on a separate line
        Assert.That(hasErrors, Is.False, comparer.GetAllErrors);
    }
}

Thanks again for the great tool!

@JonPSmith
Copy link
Owner

Hi @acblksun,

OK, to summarise your problem is with the Schema name, which matches is you ignore case. Correct?

I am planning to look at EfSchemaCompare sometime soon as I have another feature change request. I suspect I will provide a general "ignore case on table and schema names" as the dictionaries contain the combined schema + tables names. That also handles issue #9.

I will leave this open to remind me.

@acblksun
Copy link
Author

Hi @JonPSmith

That's correct. The as-built schema is lowercase product, but the EF ToTable schema argument is Product.

The casing for different schemas in this app is mixed. ie product vs Purchase, and as mentioned, there's never going to be a rebuild of production data.

Thanks again.

@JonPSmith
Copy link
Owner

HI @acblksun,

I have just released version 2.0.0 where you can use case insensitive matching. See the CaseComparer property in the CompareEfSqlConfig class.

I hope that helps you.

@acblksun
Copy link
Author

Hi @JonPSmith

That's great thanks! Just tried 2.0.0 and the new option works a treat.

Thanks again.

@naama11
Copy link

naama11 commented Dec 1, 2022

Hi @JonPSmith what is the replacement for CaseComparer when updating to version 5.3.0?

@JonPSmith
Copy link
Owner

Hi @naama11,

I moved the CompareEfSql code into the EfCore.SchemaCompare library - see Release notes on 5.0.0 .

The EfCore.SchemaCompare library doesn't support CaseCompare because there was a problem occurred in EF Core 5, so the CaseComparer is turned off.

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

No branches or pull requests

3 participants