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

Unable to use Model.ToDebugString with EF Core 6 preview 4 #24987

Closed
ErikEJ opened this issue May 27, 2021 · 7 comments
Closed

Unable to use Model.ToDebugString with EF Core 6 preview 4 #24987

ErikEJ opened this issue May 27, 2021 · 7 comments
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@ErikEJ
Copy link
Contributor

ErikEJ commented May 27, 2021

Include your code

var result =dbContext.Model.ToDebugString(MetadataDebugStringOptions.LongDefault);

And I am not able to find "DesignTimeModel" mentioned in the error message anywhere.

Include stack traces

System.InvalidOperationException: The requested configuration is not stored in the read-optimized model, please use 'DbContext.DesignTimeModel'.
   at Microsoft.EntityFrameworkCore.Metadata.SlimModel.Microsoft.EntityFrameworkCore.Metadata.IReadOnlyModel.GetChangeTrackingStrategy()
   at Microsoft.EntityFrameworkCore.Metadata.IReadOnlyModel.ToDebugString(MetadataDebugStringOptions options, Int32 indent)
   at Modelling.EfCoreModelBuilder.BuildResult(String outputPath, String startupOutputPath, Boolean generateDdl) in C:\Code\EFCorePowerTools\src\GUI\efpt30.core\EFCoreModelBuilder.cs:line 41
   at Modelling.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efpt30.core\Program.cs:line 57

Include provider and version information

EF Core version: 6.0 preview 4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0

@ErikEJ
Copy link
Contributor Author

ErikEJ commented May 27, 2021

Did some spelunking, and found this: 3be1be4
So this works:

dbContext.GetService<IDesignTimeModel>().Model.ToDebugString(MetadataDebugStringOptions.LongDefault);

I guess the issue is about updating the error message then.

@AndriySvyryd
Copy link
Member

Fixed in a60795c

@AndriySvyryd AndriySvyryd added this to the 6.0.0-preview5 milestone Jun 2, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 2, 2021
@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jun 20, 2021

@AndriySvyryd I most likely misunderstand, but what exactly was fixed in the linked 125 file PR?
I still do not see DbContext.DesignTimeModel in preview 5 !?

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jun 23, 2021

Ping?

@AndriySvyryd
Copy link
Member

@AndriySvyryd I most likely misunderstand, but what exactly was fixed in the linked 125 file PR?

Sorry, the specific fix is this is Model condition in a60795c#diff-5f6aa389ba014558ff3ca0fe47cd2c69a874c34e32f4e7ee4d7c7b4841f36748

I still do not see DbContext.DesignTimeModel in preview 5 !?

Now it's context.GetService<IDesignTimeModel>().Model, see dotnet/EntityFramework.Docs#3030

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jun 24, 2021

@AndriySvyryd Thanks :-)

@ajcvickers ajcvickers modified the milestones: 6.0.0-preview5, 6.0.0 Nov 8, 2021
@jcummings2
Copy link

Did some spelunking, and found this: 3be1be4 So this works:

dbContext.GetService<IDesignTimeModel>().Model.ToDebugString(MetadataDebugStringOptions.LongDefault);

I guess the issue is about updating the error message then.

For those like me who encountered this issue later, you may also need to add:

using Microsoft.EntityFrameworkCore.Infrastructure;

line to find the correct extension method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

4 participants