如何使用nhibernate ConfORM或至少在nhibernate ConfORM中写入sql查询来连接来自不同数据库的两个表?
这是我需要运行的查询:
select RTRIM(l.descr) as affiliation, a.LocationId
from Facilities a
join [tmt-sam2].sammi.dbo.location l ON a.LocationId = l.off_code+'-'+l.location
谢谢, 阿列克谢
答案 0 :(得分:1)
如果你没有那么多地方,你可以加载所有
using (var session1 = sessionfactoryDataBase1.OpenSession())
using (var session2 = sessionfactory_tmt_sam2.OpenSession())
{
var locations = session2.QueryOver<Location>().List();
var results = session1.QueryOver<Facility>()
.Where(f => f.LocationId.IsIn(locations.Select(l => l.OffCode + '-' + l.location)))
.AsEnumerable()
.Join(locations, f => f.LocationId, l => l.OffCode + '-' + l.location, (f, l) => new { Description = l.descr.TrimEnd(), LocationId = f.LocationId });
}
否则批量编码