question

JaySoni1910-8246 avatar image
0 Votes"
JaySoni1910-8246 asked miwan2-msft answered

How to do AutoMigration in Entityframework core without using command (Using Programming only)

I use EF core in My project and I want migrate my context using Programming (not command) So I use these two concpets one by one

1.

using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())

{
     
    var context = serviceScope.ServiceProvider.GetService<UserInformationContext>();
     
    context.Database.Migrate();

}


2.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserInformationContext userContext)

{
   userContext.Database.Migrate();

}

Problem Is ,using this two concepts can not create any Migration Folder like add-migration command Is there any way to Create Migration Folder and Migrate Context using Programming ??

dotnet-aspnet-core-generaldotnet-entity-framework-coresql-server-migration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

miwan2-msft avatar image
1 Vote"
miwan2-msft answered

Hi, @JaySoni1910-8246


From the official document of EF, we can see

EF Core will include most of the features of EF 6 gradually. However, there are some features of EF 6 which are not supported in EF Core 2.0 such as:

EDMX/ Graphical Visualization of Model
Entity Data Model Wizard (for DB-First approach)
ObjectContext API
Querying using Entity SQL.
Automated Migration
Inheritance: Table per type (TPT)
Inheritance: Table per concrete class (TPC)
Many-to-Many without join entity
Entity Splitting
Spatial Data
Lazy loading of related data
Stored procedure mapping with DbContext for CUD operation
Seed data
Automatic migration


userContext.Database.Migrate(); will update the database based on the migrations you have created. So you need to add migrations at first.



If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Best Regards,
Michael Wang



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.