Entity Framework

Solved : context has changed since the database was created. Consider using Code First Migrations to update the database

Solution:

Are you moving changes from Development Environment to staging and you are getting above error, well there is a very quick and simple solution to the problem.

Just got to database and delete this table, and it will solve the issue, given that you already have moved the changes to the required tables etc using SQL compare or any other tool.

_MigrationsHistory

Considerations and Other Solutions:

There is an other approach to automatically move the changes to database by using below code in configuration.cs file in Migrations folder.

AutomaticMigrationsEnabled = true;

Please for the love of God don’t go for drop and recreate database option, as you will lose data when accidentally code is moved to staging or production, code as given below(Warning, You will lose data by using this)

Database.SetInitializer<NameOfDbContext>(new DropCreateDatabaseIfModelChanges<NameOfDbContext>());

Visit Stack Over flow for more discussion.

Advertisements
Dotnet-Core

500.19 Error After Deploying .Net Core Solution

Solution:

The solution is very straight forward, just go to Microsoft dotnet-core website, download and install the run time along with hosting package and you are good to go.

I am using Dotnet-Core 2.1.11 on windows so I downloaded the package as highlighted below:

For some reason if you get the below error, that surely mean that you have installed wrong version of the dotnet-core, you don’t need to uninstall previously installed package for most cases, just install the correct version and you are good to go.

http error 502.5 – process failure asp.net core 2.1

Azure DevOps Server

Azure DevOps Server 2019 Stuck at Nuget Restore Step

Solution:

The solution is manual one, unless you find any automated solution.

It would stuck and display like below:

[command]D:DevOpsAgent_work_toolNuGet4.9.4x64nuget.exe restore D:DevOpsAgent_work2sAbC.sln -Verbosity Detailed -NonInteractive -ConfigFile D:DevOpsAgent_work2NugettempNuGet_247.config

So All you need to do is to go to your agent server and go to the directory

D:DevOpsAgent_work_toolNuGet4.9.4×64

and execute below command

restore D:DevOpsAgent_work2sAbC.sln -Verbosity Detailed -NonInteractive -ConfigFile D:DevOpsAgent_work2NugettempNuGet_247.config

It will restore the packages at once and you need to cancel the build and initiate again. Next time whole process will work like a charm. Please also make sure you have access to internet or source of the nuget packages.

Uncategorized

How to update the Entity Framework model, when changing stored procedure in Database

Solution:

All you need to do is to open your entity model diagram window, then click on Model Browser then go through each and delete the desired stored procedure artifacts in below folders and SAVE the file.

  1. Complex Types
  2. Function Imports
  3. Stored Procedures / Functions

Development, Entity Framework, Uncategorized

How to force Entity Framework to Always Load Fresh copy of Data from the Database

How to force Entity Framework to Always Load Fresh copy of Data from the Database

Solution:

There are many solution to achieve this result.

The most popular and easiest one is to dispose the existing context object and create new one

entities.Dispose();
entities = new Entities(); // DbContext

but it is not optimal you are disposing whole context which could be very expensive.

Optimal Solution:

Db.Entry(item).Reload(); // Db here means DbContext

this will only load the entity (item) you passed from the database and if you changed the item before reload, after reload the change will be overwritten by the values coming from database.

For more information Please check