0

I'm new to developing Dot Net projects and I've spent most of my time developing small projects with React, Next.js, and Vue.js alongside Supabase for the database.

In the ConfigureServices method, I see tutorials use options => options.UseSqlServer:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    services.AddControllersWithViews().AddRazorRuntimeCompilation();
}

What is the proper way to do the same thing but with Supabase?

I downloaded the nuget package https://www.nuget.org/packages/supabase-csharp/

but I don't see any documentation on how to use this in the ConfigureServices method.

Thank you all for your advice!

Ender91
  • 61
  • 1
  • 8
  • By using the correct EF Core provider. Does it even have one? The package you linked to is used *instead* of EF Core. If you used PostgreSQL you could use the NpgSQL EF Core provider. Since Supabase is actually a hosted service though, you can't use that. – Panagiotis Kanavos Oct 01 '21 at 14:54

2 Answers2

1

This is the documentation for supabase and I don't think this can be configured in configure services. Because you are using dbContext which is related to Entity framework if there is a package for entity framework which have support for it than you can do the following.

  • 1
    Thank you for looking into this. I was finally able to connect to Supabase. I had to remind myself what kind of DB Supabase is - it's a PostgreSQL. I just downloaded the NpgSql nuget package and followed along the steps listed here - https://www.npgsql.org/efcore/index.html The end result was this - ``` public void ConfigureServices(IServiceCollection services) { // Other DI initializations services.AddDbContext(options => options.UseNpgsql(Configuration.GetConnectionString("BloggingContext"))); } ``` – Ender91 Oct 01 '21 at 14:53
  • No problem hoped it helped. – Muhammad Jamali Oct 01 '21 at 14:55
1

you can do it with one line of code in Program.cs

builder.Services.AddDbContext<Context>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("Connection")));

"Connection" that come from appsettings.json you can find yours connection in your supabase account settings and pales it in appsettings.json

supabase had postgresql database not sqlserver