Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't make EF Code First work with manually changed data base

I've added two new properties to my domain model class and two properties to a data table accordingly. Then I tried to launch my mvc web application and got

The model backing the 'EFDbContext' context has changed since the database was created.  
Consider using Code First Migrations to update the database  
(http://go.microsoft.com/fwlink/?LinkId=238269).

Having read the following posts:

MVC3 and Code First Migrations

EF 4.3 Automatic Migrations Walkthrough

I tried to Update-Database through Package Manager Console, but got an error

Get-Package : Не удается найти параметр, соответствующий имени параметра "ProjectName".
C:\Work\MVC\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:611 знак:40
+     $package = Get-Package -ProjectName <<<<  $project.FullName | ?{ $_.Id -eq 'EntityFramework' }
+ CategoryInfo          : InvalidArgument: (:) [Get-Package], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,NuGet.PowerShell.Commands.GetPackageCommand

The EntityFramework package is not installed on project 'Domain'.

But the Entityframework is installed on project Domain. I removed it from references, deleted package.config and sucessfully reinstalled EF. But Update-Database still returns same error. Update-Database -Config does as well

What am I doing wrong?

EDIT

Many thanks to Ladislav Mrnka, I'll try to rephrase my question. As far as I changed my data table manually, I am not expected to use migration. But how can I now make EF work with manually edited domain model class and data table?

like image 244
horgh Avatar asked Nov 29 '22 02:11

horgh


1 Answers

Try to add this to startup of your application (you can put it to App_Start):

Database.SetInitializer<EFDbContext>(null);

It should turn off all logic related to handling the database from EF. You will now be fully responsible for keeping your database in sync with your model.

like image 121
Ladislav Mrnka Avatar answered Dec 05 '22 02:12

Ladislav Mrnka