简体   繁体   English

如何将 ASP.NET Core 5 MVC 项目连接到 Supabase 数据库而不是 SQL 服务器?

[英]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.

相关问题 如何在 Asp.Net Core Mvc 5.0 中将 sql 数据库与 ado.net 连接? - How to connect sql Database with ado.net in Asp.Net Core Mvc 5.0? 如何将ASP.Net Core MVC2项目连接到远程数据库 - How to connect an ASP.Net Core MVC2 project to a remote database 当我从另一个用户运行我的 ASP.NET Core MVC 解决方案时,它没有连接到 SQL Server 数据库 - When I run my ASP.NET Core MVC solution from another user it does not connect to the SQL Server database 如何在Visual Studio(C#)中将ASP.NET项目与SQL Server数据库表连接 - How to connect ASP.NET project with SQL Server database table in Visual Studio (C#) 如何在ASP.NET Core项目中指向我的完整SQL Server Express数据库? - How do I point to my full SQL Server Express database in ASP.NET Core project? ASP.NET 核心如何上传图片到SQL服务器数据库? - ASP.NET Core how to upload image to SQL Server database? 如何在 ubuntu 桌面上使用 Entity Framework Core 将 asp.net core MVC 项目连接到本地数据库 - how to connect asp.net core MVC project to local DB using Entity Framework Core on ubuntu desktop 如何仅通过添加ADO.NET实体数据模型ASP.NET MVC 3连接到SQL Server数据库和获取数据 - How to Connect to SQL Server Database and Fetch datas by Just adding ADO.NET Entity Data model ASP.NET MVC 3 如何从托管在 **1&amp;1 Ionos** 托管服务器中的 ASP.NET Core 2.2 连接 MS SQL Server 数据库? - How to connect MS SQL Server database from ASP.NET Core 2.2 hosted in **1&1 Ionos** hosting server? 尝试连接 SQL 服务器和 ASP.NET MVC mvc 应用程序 - Trying connect SQL Server and ASP.NET MVC mvc app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM