Reputation: 2822
I'm trying to set up a db context in a .net core F# web app. As part of this I need to convert the following in to F#:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
My F# version is:
services.AddDbContext<ApplicationDbContext>(fun (options: DbContextOptionsBuilder) ->
options.UseSqlite(this.Configuration.GetConnectionString("DefaultConnection")))
However, I am getting the following exception:
No overloads match for method 'AddDbContext'. The available overloads are shown below (or in the Error List window).property Startup.Configuration: IConfigurationRoot
What could the problem be?
Upvotes: 2
Views: 447
Reputation: 1
UseSqlite
return Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
value, so you need ignore it to match Action<DbContextOptionsBuilder>
.
services.AddDbContext<ApplicationDbContext>(fun (options: DbContextOptionsBuilder) ->
options.UseSqlite(this.Configuration.GetConnectionString("DefaultConnection")) |> ignore)
Upvotes: 0
Reputation: 2822
The problem was that I hadn't added a constructor for ApplicationDbContext that takes a DbContextOptions as a parameter. After changing the default constructor to
type ApplicationDbContext(options: DbContextOptions<ApplicationDbContext>) =
inherit IdentityDbContext<ApplicationUser>(options)
I could compile
Upvotes: 1