我的应用程序有2个数据库,
Db1
(有表格
dbo.Student
)和
Db2
(有表格
dbo.School
). 我创建了2个AppService来访问它们
当我试图从他们两个获取数据时,它只使用连接到
(找不到表
dbo。学校
在当前上下文中)。那么,如何同时从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:
我试图在学生之前找到学校,但面临以下错误:
传入的事务与当前
联系仅与当前连接关联的事务
可以使用。