The model backing the 'POSContext' context has changed since the database was created - entity-framework

I am developing winform application using entityframework in visual studio 2012 with database first approach. Suddenly I am facing the following error:-
The model backing the 'POSContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Can any please immediately help me to resolve this issue. I shall be very thankful for timely help.
Thanks.

make sure that you don't have a database initialized. Only have to call it once so you could put it in a static constructor of your DbContext class
Database.SetInitializer<YourDbContext>(null);

Related

Entity Framework - Update database manually

I am new to entity framework and using EF 6.1.1... using code first approach i have generated the database..
When i run my application from Visual Studio in my local machine..
and update a record from my application.. it immediately reflects in ui immediately..
but if i update the records in database manually.. then the changes are not reflected immediately in ui.. i need to rebuild the solution to and run it again to bring the updated data to ui..
Just need to know if this is how entity framework works?? if yes, is there a way to make the ui to sync with database even for manual updates without rebuilding the solution..
Please let me know if you need any other information..

Create databasebase with entity framework code first approach

I do not want that my database is created when I insert a record. One reason is I do not want to create sample application, do an insert just to have a database...
I want that my database is created via the package manager console.
How can I do that?
It's a little unclear what you're asking, but I think you're trying to prevent the database from being created automatically from the application code.
The database is created on the first use of the DataContext. If you don't want the database to be created on the first use of the data context you can add Database.SetInitializer<YourContextClassHere>(null); to your Global.asax.cs file.
Then you could use the Update-Database cmdlet in Visual Studio to run the pending migrations including creating the database.

Database.SetInitializer not working

I'm facing a strange problem, I'm trying to run a method that explicitly migrates my database to the latest version withing EF code first, how ever when I run the method, nothing happened, heres my method that intends to migrate the database:
public void migrate()
{
Database.SetInitializer(
new MigrateDatabaseToLatestVersion<Alumnosdb, Migrations.Configuration>()
);
}
when I get to this method by way of debugging and hover over at Database, the connection states is closed and nothing happened.
Here is a snapshot where the problem occurs:
http://s8.postimg.org/r20k94ifp/errormigrate.png
Hopefully someone can point me on how to migrate my schema by way of code cause it seems the way that I'm trying to achieve this is not working, so any advice would be really appreciate it.
This just sets the initializer, not runs it. It will run when you actually use DbContext session.

How to disable code-first feature in EF (MVC4 Visual Studio 2012)

How to disable code-first feature in EF (Visual Studio 2012)
I am using Visual Studio 2012, MVC4 (Internet application template).
I want to use EF, but not with its code-first feature. I would want the application to error out, rather than create or modify my database based on my code. (i just can not live with this feeling of my database being changed behind the scenes ... i want the application to use the exact db i have created ... and if there is any thing that has to be changed, i'll do it my self)
is this possible with the new Ef (VS2012)?
i have seen many people asking this, but so far i am unable to find the answer.
You can use Code First and ensure that your database never gets updated or overwritten when you change your model by setting the database initializer to null:
Database.SetInitializer<MyDbContext>(null);
It's a static method of the Database class and should be called at the beginning of your application, for example in global.asax or in a static constructor of your context class. Doing this you have to change model class and database schema manually so that they match.
You can also use the Reverse Engineer feature to create a Code First model from an existing database. It is explained here: http://msdn.microsoft.com/en-us/data/jj200620
Or if you don't want to use Code First at all and work with a model designer you can use the Database First approach, explained here: http://msdn.microsoft.com/en-us/data/jj206878
An overview about all the possible options is here: http://msdn.microsoft.com/en-us/data/ee712907.aspx

Visual Studio Entity-Framework-Designer: Update model from database broken by custom provider

We have decorated the default Entity Framework provider to support custom ExpressionsVisitors. So far everything works out the way we intend it to be.
After adding the custom provider entry into the machine.config and placing the Custom Provider Assembly in the machine’s GAC the entity framework designer was not broken any more and did show up correctly.
However the command “Update model from database...” just ends in a message box stating that:
An exception of type 'Microsoft.VSDesigner.Data.Local.ConnectionStringConverterServiceException' occurred while attempting to update from the database. The exception message is: ''.
We’re using VS Premium 2012 with .net 4.5.
Where does this error come from and what needs to be done to fix it?
Any Help or Advice Gladly Appreciated