我的应用程序有 2 个数据库,Db1
(有表dbo.Student
)和Db2
(有表dbo.School
)。我创建了 2 个 AppService 来访问它们当我尝试从它们两者中获取数据时,它只使用到(在当前上下文中Db1
找不到表)的连接。dbo.School
那么如何同时从 Db1 和 Db2 获取数据
private readonly IStudentAppService _studentAppService;
private readonly ISchoolAppService _schoolAppService;
public BranchAccountController(IStudentAppService studentAppService,
ISchoolAppService schoolAppService)
{
_studentAppService = studentAppService;
_schoolAppService = schoolAppService;
}
public async Task<PartialViewResult> GetStudent(int? id)
{
//Repository 1 (Database 1)
var student = await _studentAppService.GetStudentForEdit(new NullableIdDto { Id = id });
//Repository 2 (Database 2)
var school = await _schoolAppService.GetSchoolList();
//bla bla
}
更新1:我试图在学生之前获得学校并面临以下错误:传入的交易与当前连接无关。只能使用与当前连接关联的事务。