C# 对正确数据库的Dapper存储过程调用
我有以下单一数据库结构:C# 对正确数据库的Dapper存储过程调用,c#,asp.net,dapper,C#,Asp.net,Dapper,我有以下单一数据库结构: Server | Database + Tables + Programmability(stored procedures) 其中,我使用以下方法使用Dapper进行存储过程调用: public List<Events> GetEvents() { using (var connection = new SqlConnection(SQLSettings.GetConnectionString())) {
Server
|
Database
+ Tables
+ Programmability(stored procedures)
其中,我使用以下方法使用Dapper进行存储过程调用:
public List<Events> GetEvents()
{
using (var connection = new SqlConnection(SQLSettings.GetConnectionString()))
{
return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
}
我的问题是,我需要如何修改我的方法以确保它命中存储过程所在的正确数据库?您使用正确的连接字符串来确保它
using (var connection = new SqlConnection("Connection string of the first db"))
{
return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
using (var connection = new SqlConnection("Connection string of the second db"))
{
return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
使用(var-connection=new-SqlConnection(“第一个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}
使用(var connection=newsqlconnection(“第二个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}
您正在确保使用正确的连接字符串
using (var connection = new SqlConnection("Connection string of the first db"))
{
return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
using (var connection = new SqlConnection("Connection string of the second db"))
{
return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
使用(var-connection=new-SqlConnection(“第一个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}
使用(var connection=newsqlconnection(“第二个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}
假设您知道在哪个DB(1或2)中查找SP,请使用以下任一选项:
using (var connection = new SqlConnection(SQLSettings.GetConnectionString1()))
{ ... }
或
假设您知道要在哪个DB(1或2)中找到SP,请使用以下任一选项:
using (var connection = new SqlConnection(SQLSettings.GetConnectionString1()))
{ ... }
或
它使用的数据库是基于连接字符串的。我认为它很简单。感谢大家的快速回复。它使用的数据库是基于连接字符串的。我觉得这很简单。谢谢大家的快速回复。