Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# data access and EF migrations

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

I want to use type providers for data access, but would love to have entity framework migrations.

Can I use EF migrations without entity framework? I am fine with writing migration code by hand, hopefully in F#.

like image 527
Haraakiri Yaar Avatar asked Apr 15 '14 05:04

Haraakiri Yaar


People also ask

What does ⟨F⟩ mean?

This sound is usually considered to be an allophone of /h/, which is pronounced in different ways depending upon its context; Japanese /h/ is pronounced as [ɸ] before /u/. In Welsh orthography, ⟨f⟩ represents /v/ while ⟨ff⟩ represents /f/. In Slavic languages, ⟨f⟩ is used primarily in words of foreign (Greek, Latin, or Germanic) origin.

What does the letter F mean in math?

In countries such as the United States, the letter "F" is defined as a failure in terms of academic evaluation. Other countries that use this system include Saudi Arabia, Venezuela, and the Netherlands. In the hexadecimal number system, the letter "F" or "f" is used to represent the hexadecimal digit fifteen (equivalent to 15 10 ).

What does F stand for in the Etruscan alphabet?

In the Etruscan alphabet, 'F' probably represented /w/, as in Greek, and the Etruscans formed the digraph 'FH' to represent /f/.

Is the letter F doubled at the end of words?

It is often doubled at the end of words. Exceptionally, it represents the voiced labiodental fricative / v / in the common word "of". F is the twelfth least frequently used letter in the English language (after C, G, Y, P, B, V, K, J, X, Q, and Z ), with a frequency of about 2.23% in words.


3 Answers

In the case where you want to use EFCore, it's possible to isolate only the migrations in a C# project with MigrationsAssembly.

For example in a 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

Services 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 a work in progress project to support F# design-time: https://github.com/bricelam/EFCore.FSharp

like image 133
akhansari Avatar answered Oct 19 '22 10:10

akhansari


F# type providers imply that there is already external data source i.e. they are inherently "Db First". Using EF Code First only to automatically generate migrations is not the best idea, I recommend plain SQL and some tools to keep track of migrations such as dbup. I answered it in details in similar but bigger question.

like image 3
KolA Avatar answered Oct 19 '22 09:10

KolA


You can certainly use EF migrations without using EF in your app. Create a separate project and use Code First migrations.

I'm not aware that the migrations scaffolding feature supports F#. Either suffer with C# for migrations or translate the code yourself?

like image 2
Craig Stuntz Avatar answered Oct 19 '22 09:10

Craig Stuntz