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 pedning migrations with EF Core 6 #24448

Closed
ErikEJ opened this issue Mar 19, 2021 · 7 comments
Closed

Getting pedning migrations with EF Core 6 #24448

ErikEJ opened this issue Mar 19, 2021 · 7 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 19, 2021

I am using this with EF Core 5, but get Obsolete warnings:
'TypeMappingConvention' is obsolete: 'Use IModelRuntimeInitializer.Initialize instead.'
'RelationalModelConvention' is obsolete: 'Use IModelRuntimeInitializer.Initialize instead.'

Not really sure how to proceed...

            var migrationsAssembly = context.GetService<IMigrationsAssembly>();
            var modelDiffer = context.GetService<IMigrationsModelDiffer>();
            var dependencies = context.GetService<ProviderConventionSetBuilderDependencies>();
            var relationalDependencies = context.GetService<RelationalConventionSetBuilderDependencies>();

            var hasDifferences = false;

            if (migrationsAssembly.ModelSnapshot != null)
            {
                var typeMappingConvention = new TypeMappingConvention(dependencies);
                typeMappingConvention.ProcessModelFinalizing(((IConventionModel)migrationsAssembly.ModelSnapshot.Model).Builder, null);

                var relationalModelConvention = new RelationalModelConvention(dependencies, relationalDependencies);
                var sourceModel = relationalModelConvention.ProcessModelFinalized(migrationsAssembly.ModelSnapshot.Model);

                hasDifferences = modelDiffer.HasDifferences(
                     ((IMutableModel)sourceModel).FinalizeModel().GetRelationalModel(),
                    context.Model.GetRelationalModel());
            }

            var pendingModelChanges = (!databaseExists || hasDifferences);

EF Core version: 6.0
Target framework: NET 5.0

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Mar 19, 2021

This is tracked at dotnet/EntityFramework.Docs#3030

var snapshotModel = migrationsAssembly.ModelSnapshot?.Model;

if (snapshotModel is IMutableModel mutableModel)
{
    snapshotModel = mutableModel.FinalizeModel();
}

if (snapshotModel != null)
{
    snapshotModel = context.GetService<IModelRuntimeInitializer>().Initialize(snapshotModel);

    hasDifferences = modelDiffer.HasDifferences(snapshotModel.GetRelationalModel(), context.Model.GetRelationalModel());
}

However in preview3 the last line should be:

    hasDifferences = modelDiffer.HasDifferences(snapshotModel.GetRelationalModel(), context.DesignModel.GetRelationalModel());

@AndriySvyryd AndriySvyryd added the closed-no-further-action The issue is closed and no further action is planned. label Mar 19, 2021
@ErikEJ
Copy link
Contributor Author

ErikEJ commented Mar 20, 2021

Thanks, just had to change:

.Initialize(snapshotModel, null)

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Apr 20, 2021

@AndriySvyryd - did this not make it into 6.0 preview 3?

//TODO 6.0 preview 3!
 hasDifferences = modelDiffer.HasDifferences(snapshotModel.GetRelationalModel(), context.DesignModel.GetRelationalModel())

@AndriySvyryd
Copy link
Member

@ErikEJ No and for preview4 we changed the API to

hasDifferences = context.GetService<IMigrationsModelDiffer>().HasDifferences(
    snapshotModel.GetRelationalModel(),
    context.GetService<IDesignTimeModel>().Model.GetRelationalModel());

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Apr 20, 2021

Hmmm.. not exactly intuitive! Thanks.

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Apr 20, 2021

That's by-design 😄. We think that very few users would actually need that and if it turns out to be false, then we'll introduce an even simpler sugar API where the code in #24448 (comment) is replaced by a single call.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Apr 20, 2021

You are probably right, I am the only person in the world who cares!

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants