locked
Entity Framework Timeout Citing Pending Model Changes RRS feed

  • Question

  • User-939035612 posted

    First, I never did a code first migration before installing Identity and have not done one since because I do all my DB design work using SSMS. Lately I have been getting a timeout error after adding new columns to tables in my database and updating my EF model to consume those columns. There are also other times when my page loads but the new fields of data are empty. 

    I can't think of any pending changes that need to be made to the DB since I already made them using SSMS. I just need to pull data from the new columns without anything timing out. I am also puzzled by the timeout since the database is on the same machine and has been running the entire time. I don't want to get into the habit of changing the design of my DB using code in Visual Studio. I never would have used it in the first place had it not been necessary to install Identity.

    The error I get looks like this:

    A database operation failed while processing the request.
    SqlException: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Win32Exception: The wait operation timed out.
    There are pending model changes for ApplicationDbContext
    In Visual Studio, use the Package Manager Console to scaffold a new migration for these changes and apply them to the database:
    
    PM> Add-Migration [migration name]
    PM> Update-Database
    Alternatively, you can scaffold a new migration and apply it from a command prompt at your project directory:
    
    > dotnet ef migrations add [migration name]
    > dotnet ef database update

    Thursday, December 19, 2019 2:58 AM

All replies

  • User475983607 posted

    My best guess is you manually updated Entity Framework entities after updating the database using SSMS.  At least that what the error indicates.  You'll need to scaffold the entities every time the database is updated with SSMS.

    https://docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding

    https://www.learnentityframeworkcore.com/walkthroughs/existing-database

    Identity can complicate this process if the Identity tables and application tables are within the same database.  Identity uses migrations to build tables and this process (Code First) tracks changes to the entities.  You'll want to have separate Identity and application databases and DB Contexts.  This will allow you to update Identity using Code First if there are any changes to the libraries in the future. 

    Thursday, December 19, 2019 11:51 AM
  • User-939035612 posted

    Everything is in the same database and DB context except for entity tables because when I tried to scaffold those in the past I got an error about the entities conflicting with Identity. 

    Your guess is correct, I did manually update the entities after adding new columns to a couple tables in SSMS, but I can access the data just fine now. That still does not explain why the connection timed out. So what if there is a pending migration, that should not cause a timeout. On top of that the application runs extremely slow at times. At first I thought it might be due to something in Visual Studio, but now I am wondering if this might have something to do with it. Is there something going on behind the scenes that would explain the slower performance?

    Friday, December 20, 2019 6:11 AM
  • User475983607 posted

    Everything is in the same database and DB context except for entity tables because when I tried to scaffold those in the past I got an error about the entities conflicting with Identity. 

    Everything is in the same database and DB context except for entity tables?  You have two databases?

    Is there something going on behind the scenes that would explain the slower performance?

    Performance is related to design.  SQL Server has tools to figure out what's going on.  The SQL Server Profiler lets you see the queries being executed and the amount of time each query takes.  Copy the query and check out the execution plan SSMS.

    https://docs.microsoft.com/en-us/sql/relational-databases/performance/monitor-and-tune-for-performance?view=sql-server-ver15

    Friday, December 20, 2019 12:46 PM
  • User-939035612 posted

    I'll check that out but I can't help thinking the problem is with the application and not the database since the original website working with the same database did not have this problem.

    Saturday, December 21, 2019 12:25 AM
  • User475983607 posted

    I'll check that out but I can't help thinking the problem is with the application and not the database since the original website working with the same database did not have this problem.

    Your responses are bit cryptic.  I assume you got passed the migration error.  You have a new issue where querying the database cause a timeout.  If this is the case then the first step is taking a look at the query.

    Saturday, December 21, 2019 3:31 PM