Database.SetInitializer not working - entity-framework

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.

Related

Iterable has value but when i try to pass it in functions or convert it to list it appears to be null

I have a Future that returns a value of type Iterable<Contact> from the Flutter plugin contacts-service.
My code is like this:
var contacts = await ContactsService.getContacts();
But if I try to print it for example it throws an exception that the input cannot be null.
The same happens if I try to run .toList().
But as you can clearly see in the following picture the object has data.
I'm really stuck and I'd appreciate the help.
To whoever comes to this thread looking for the answer.
I made an issue to the flutter repo, they told me to make an issue to the library that I was using.
I made an issue to the library repo, they told me it works just fine when finally another person had the exact problem. The issue in the library is now closed and a google employee that I'm following on github made a null-safety-test. So you're not crazy after all. It's just a bug. A rare one, but a bug none the less!

Error: The model backing the 'NameDbContext' context has changed since the database was created

The original issue I was trying to solve was related to this error message. This is happening in a Web API 2 Project running on Azure.
Error 1
Introducing FOREIGN KEY constraint 'FK_dbo.Merchant_MerchantId' on table 'Keys' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION,or modify other FOREIGN KEY constraints.
The FOREGIN KEY error message was only introduced after I tried to upload a release build of my API to my Azure App Service. I recently upgrade to version 15.9.11 of Visual Studio 2017, but I have no idea if that is the cause of the FOREIGN KEY issue that started this mess. This API and database has been running for years with no problems whatsoever.
To try and fix the problem, I added the following line to my OnModelCreating(DbModelBuilder modelBuilder) method.
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
Adding the line kind of fixed the issue and Error 1 has gone away, but now the API is not finding records that are actually in the database. I'm not sure why that is.
I have since commented out the line and uploaded a new build of my App Service. I'm now getting this error message.
Error 2
Error: The model backing the 'NameDbContext' context has changed since the database was created.
At this stage, I'm causing more problems instead of fixing my original problem.
Any help to recover from this mess is much appreciated! Thanks!
UPDATE 1
I worked with a Microsoft Engineer on the "The model backing the 'NameDbContext' context has changed since the database was created" error. I added the following to the Application_Start() in the Global.asax.cs file. Adding this did not delete or alter any of my data in SQL. Error message 2 has gone away. The API is still not returning records that are in the database, so I still have a problem to fix.
Database.SetInitializer<FaceOffersDbContext>(null);
UPDATE 2
I ran my API locally with no problems. This means that the problem is only happening in Azure. I'm working with Microsoft to narrow down the issue and come up with a fix.
It seems your database schema is changed and not at per with your entity framework, You may try to forcefully update your database using package manager console.

Call to a member function getDateFormat() on null, laravel/passport install

I am getting a
[Symfony\Component\Debug\Exception\FatalThrowableError] Call to a member function getDateFormat() on null
when running "php artisan passport:install" on a laravel/mongodb api project. I have tried changing "use Illuminate\Database\Eloquent\Model;" to "use Jenssegers\Mongodb\Eloquent\Model as Model;" in my user and client.php but it still throws the exception.
any ideas??
I also encountered this problem while developing a same type of project. This occurs because Laravel Passport doesn't support Jenssegres\laravel-mongodb. It uses the Illuminate\Database\Eloquent\Model by default.
Now there are two solutions to this.
You can go on changing every Illuminate\Database\Eloquent\Model to Jenssegres\Mongodb\Eloquent\Model in the Laravel Passport's vendor folder(there are about 6 files you will have to change), but this is not recommended, as when you will try you push this project on the production server, the vendor folder is ignored, and you will have to do all the changes again. Also if they change something and you update it, all the changes will be lost.
Another way of doing this, which I would recommend is, using designmynight/laravel-mongodb-passport package. This package will do the above-stated things and will do it efficiently. Installation is also pretty simple. You can go through the documentation here and you can have it up and running in no time.
Hope this can solve your problem.
Documentation link: https://github.com/designmynight/laravel-mongodb-passport

Trying to upgrade, from EF4.1 to EF6.1, ObjectContext reference code?

I am trying to upgrade my MVC3/.NET4.5 application to use EF6.1, in the main part for its performance improvements.
One of my problem code lines is :
private AppEntities db = new AppEntities();
I have removed system.data.entity from references and web.config, but this line still seems to be looking for this dll. I did try and add:
using System.Data.Entity.Core.Objects.ObjectContext;
Did not seem to fix the issue with AppEntities line trying to find system.data.Entity v4.0.0.0
Many thanks
EDIT:
I managed to sort this by adding:
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
to AppEntities.cs file.
Also needed to add to some of the POCO files.
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
It all builds fine.
However my problem now is that it seems to take an age to show the page on first load, guess this is to do with native code creation. Also I have heard that much EF code that was native in .NET is now MSIL in Entity Framework.dll and thus need compiling to native code as well. Perhaps this is what is causing my pain, see: EF6 Warm up metrics

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

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);