waf / CSharpRepl

A command line C# REPL with syntax highlighting – explore the language, libraries and nuget packages interactively.
https://fuqua.io/CSharpRepl/
Mozilla Public License 2.0
2.76k stars 106 forks source link

How to use against a project with EF Core and Postgres? #355

Open AndiRudi opened 5 months ago

AndiRudi commented 5 months ago

I want to start a csharprepl against an existing asp.net core app with entity framework and postgres as the database. The idea is to play with the project and especially also query the database using the models in the project. I couldn't get it to work after quite some time and maybe someone can help.

I am starting the repl normally with csharprepl but I also tried csharprepl --framework Microsoft.AspNetCore.App which did not change anything, so maybe this is not related?!

Anyway then I am starting with the following lines

#r "./MyProject/MyProject.csproj"
#r "nuget: Microsoft.EntityFrameworkCore, 8.0.3.0"
#r "nuget: Npgsql.EntityFrameworkCore.PostgreSQL, 8.0.2"

using MyProject;
using Microsoft.EntityFrameworkCore;

var optionsBuilder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<MyDbContext>();
optionsBuilder.UseNpgsql("....");

var context = new MyProject.MyDbContext(optionsBuilder.Options);

and I get the following error:

(9,1): error CS1929: 'DbContextOptionsBuilder<MyDbContext>' does not contain a definition for 'UseNpgsql', 
and the best extension method overload 'NpgsqlDbContextOptionsBuilderExtensions.UseNpgsql(DbContextOptionsBuilder, 
Action<NpgsqlDbContextOptionsBuilder>?)' requires a receiver of type 'DbContextOptionsBuilder'.

I have a clue that the wrong extension method is used, but I am stuck to figure out why... Is this a bug?