2

如何使用 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

谢谢, 阿列克谢

4

1 回答 1

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 });
}

否则代码中的批次

于 2011-10-21T06:54:26.427 回答