How to create an instance of dbContext in Entity Framework Core Migrations? - entity-framework-core

Is it possible to create an instance of my dbContext in my Entity Framework Core migrations? Is this a supported feature? I can't seem to get an instance via Migration or MigrationBuilder

Related

Per request instance of Entity Framework db in ASP.NET with unity

I have an ASP.NET MVC 4 application and I need to create dbContext for Entity Framework database with a lifetime of "per request".
How can I do this with Unity container?
PS: I use dependency injection of the dbContext.

Entity Framework Core migrations compatibility

I know that Entity Framework migrations aren't compatible with Entity Framework Core, but I could not find a statement clarifying whether Entity Framework Core migrations are guaranteed to be compatible with all future versions of Entity Framework Core. Is there any such statement?
No. But EF -> EF Core was a rewrite, with lots of breaking changes. There is nothing like that planned for the future.
But worst-case scenario you would need to Reset All Migrations.

Migrating from EF 6.1.2 to EF Core (2.1). How to deal with the Migrations?

As performance of our application is lack lustre we may try to migrate it from using Entity Framework 6.1.2 to Entity Framework Core 2.1. I cannot find a clear overview what pitfalls there will be. I do not expect too much problems arising from the need to rewrite some queries, but I am especially wondering what needs to be done about our 30+ migrations that we have for the database.
Are there examples on how to migrate Migrations from EF 6 to EF-core 2.1?
If you have EF 6 as Database-First and EF Core is Code-First. You can use reverse POCO generator. Then run Add-Migration to generate migration. Now you have to take care, You need to remove the changes from Up method. Now run Update-Database. From now onwards follow Code-first approach. you make changes in model, generate migration and run Update-Database.
Welcome yo EF Core.

Updating my EF model to use 4.1 when I built it in 4.0

I built my EF Model in EF 4.0, and then installed the 4.1 upgrade that includes the new DBContext interface. How do I update my model so that it uses the 4.1 features going forward?
Thank You
You can use DbContext with your EDMX model. After installing EFv4.1 you should have new T4 template available: DbContext generator. This will take your EDMX and create context derived from DbContext and all POCO entities for you. Here you have walkthrough.
But if you want to switch to DbContext just because of DbContext.Entry.State you don't have to. EFv4 has a similar mechanism:
context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
Here is the full description how to update an entity in EFv4.
What beneftis are you hoping to see by upgrading from EF4.0 to 4.1? You're obviously not going to benefit from using model-first development since you already have an existing model. You can already generate POCO objects from EF4.0. See Entity Framework upgrade from v4 to v4.1(RC)

entity framework 4.1 objectContext vs dbContext [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext)
Should I use ObjectContext or DbContext? What's the best way?
I am currently using DbContext in a Database first situation and it is working fine. DbContext is NOT only for Code First development.
DbContext acts like a wrapper around the ObjectContext. Julie Lerman has a nice explanation, how you can access the ObjectContext that is inside of DbContext here. So if you decide to use DbContext, you can still solve things with ObjectContext if you need to.
DbContext simplifies common tasks. One example is the Find() method.
Product p = db.Products.Find(id);
ObjectContext for version 4.0 when using a designer generated model and DbContext with a 4.1 Code First model.
It seems like when you use the designer generated model it automatically defaults to ObjectContext anyway