Access to F # Data and EF Migration

I have been using F # for some time and really love it.

I want to use type providers to access data, but would like to have entity structure migration.

Can I use EF migrations without entity frames? I am fine with writing the migration code manually, hopefully in F #.

+7
f # entity-framework code-first-migrations ef-migrations
source share
3 answers

You can use EF migration without using EF in your application. Create a separate project and use Code First migration .

I do not know that the motion support function supports F #. Either suffer with C # for migration, or translate the code yourself?

+1
source share

Providers such as F # imply that an external data source already exists, that is, they are essentially β€œDb First”. Using EF Code First only to automatically generate migrations is not a good idea, I recommend simple SQL and some migration tracking tools like dbup. I answered in detail a similar but larger question.

+1
source share

In case you want to use EFCore, you can isolate only migrations in a C # project using MigrationsAssembly .

For example, in the DbContext module:

 let setupOptions (optionsBuilder: DbContextOptionsBuilder) = optionsBuilder.UseNpgsql( "Host=localhost;Database=mydb;Username=postgres;Password=postgres", fun opt -> opt.MigrationsAssembly "MyProject.Data.Migrations" |> ignore) |> ignore 

Service Configuration:

 services.AddDbContext<DbContext.MyDbName>(DbContext.setupOptions) 

CLI:

 dotnet ef migrations add CreateFoo -p ./MyProject.Data.Migrations -s ./MyProject.Api -v dotnet ef database update -p ./MyProject.Data.Migrations -s ./MyProject.Api -v 

There is also an unfinished project to support F # development time: https://github.com/bricelam/EFCore.FSharp

0
source share

All Articles