[英]How to connect ASP.NET Core 5 MVC project to Supabase database instead of SQL Server?
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.我是开发 Dot Net 项目的新手,我大部分时间都在使用 React、Next.js 和 Vue.js 以及数据库的 Supabase 开发小型项目。
In the ConfigureServices
method, I see tutorials use options => options.UseSqlServer
:在
ConfigureServices
方法中,我看到教程使用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?除了使用 Supabase 之外,做同样事情的正确方法是什么?
I downloaded the nuget package https://www.nuget.org/packages/supabase-csharp/ 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.但我没有看到任何关于如何在
ConfigureServices
方法中使用它的文档。
Thank you all for your advice!谢谢大家的建议!
This is the documentation for supabase and I don't think this can be configured in configure services.这是supabase的文档,我认为这不能在配置服务中进行配置。 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.
因为您使用的是与实体框架相关的dbContext ,如果存在支持它的实体框架的 package,那么您可以执行以下操作。
you can do it with one line of code in Program.cs您可以使用 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来自appsettings.json的“连接”你可以在你的supabase帐户设置中找到你的连接,并在appsettings.json
supabase had postgresql database not sqlserver supabase 有 postgresql 数据库不是 sqlserver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.