使用命名 sql 查询进行全文索引搜索时 NHibernate 中的异常
我正在使用视图 vw_SearchSite 实现全文搜索,该视图具有所有可搜索字段并返回具有与搜索结果相同的站点 ID 的站点。
查询:
……
<return alias="site" class="Site"/>
SELECT DISTINCT {site.*}
FROM v_Site {site}
WHERE {site}.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.*,:pattern)
)
实现:
public Site[] GetSitesforSearch(string search)
{
using (var session = GetSession())
{
var q1 = session.GetNamedQuery("SearchSite").SetString("pattern", search);
var q2 = q1.List<Site>().ToArray();
return q2;
}
}
单元测试时的异常:
in expected: {site} [SELECT DISTINCT {site.*}
FROM v_Site {site}
WHERE {site}.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.*,:pattern)
)]
我对本地主机数据库拥有完全权限。我尝试了上述代码的所有排列和组合,但未能找到解决办法。当我在 SQL SERVER Management Studio 中执行该查询时,该查询工作得非常好。
这是我的单元测试:
public void Getsitesforsearch_returns_all_matching_sites_test() { //安排 const 字符串搜索 = "abc"; var 国家 = _entityBuilder.CreateCountry(); Country.Name = "墙国家"; var Country1 = _entityBuilder.CreateCountry(); Country.Name = "蹩脚的国家"; var state1 = _entityBuilder.CreateState(); state1.Country = 国家; var state2 = _entityBuilder.CreateState(); 国家2.国家=国家1; state1.Name = "墙状态"; state1.Abbreviation = "WS"; state2.Name = "废话"; state2.Abbreviation = "CR";
var site1 = _entityBuilder.CreateSite();
var site2 = _entityBuilder.CreateSite();
var site3 = _entityBuilder.CreateSite();
var site4 = _entityBuilder.CreateSite();
site1.Name = "abc";
site1.City = "wallsite";
site1.PostalCode = "33333";
site1.State = state2;
site2.State = state2;
site2.City = "wallsite";
site2.PostalCode = "44444";
site2.Name = "site wall";
site3.State = state1;
site3.City = "wallsite";
site3.PostalCode = "55555";
site3.Name = "site";
site4.City = "walstreet";
site4.PostalCode = "66666";
site4.Name = "site wall";
site4.State = state2;
PersistEntities(state1, state2, country1,country);
PersistEntities(site1,site2,site3,site4);
var sites = new[] {site2,site3,site4};
//Act
var repository = CreateRepository();
var result = repository.GetSitesforSearch(search);
//Assert
result.ShouldNotContain(site1);
result.ShouldEqual(sites) ;
result.ShouldContain(site2);
result.ShouldContain(site3);
result.ShouldContain(site4);
}
这是错误:
SiteRepositoryTester.Getsitesforsearch_returns_all_matching_sites_test:失败
NHibernate:选择 deviceinst0_.Id 作为 Id5_,deviceinst0_.Name 作为 Name5_,deviceinst0_.Latitude 作为 Latitude5_,deviceinst0_.Longitude 作为 Longitude5_ 、deviceinst0_.InstallationDate 为 Installa5_5_、deviceinst0_.RemovalDate 为 RemovalD6_5_、deviceinst0_.DeviceId 为 DeviceId5_、deviceinst0_.PrimaryGroupId 为 PrimaryG8_5_、deviceinst0_.SecondaryGroupId 为来自 tg.v_DeviceInstall deviceinst0_ 的 Secondar9_5_ NHibernate:从 tg.vw_BaseStation basestatio0_ 选择 basestatio0_.BaseStationId 作为 BaseStat1_4_、basestatio0_.BaseId 作为 BaseId4_、basestatio0_.InstalledOn 作为 Installe3_4_、basestatio0_.SiteId 作为 SiteId4_ NHibernate:从 tg.v_Threshold Threshold0_ 中选择阈值0_.Id 作为 Id8_、阈值0_.ReadingTypeId 作为 ReadingT2_8_、阈值0_.UpperBound 作为 UpperBound8_、阈值0_.LowerBound 作为 LowerBound8_、阈值0_.DeviceInstallId 作为 DeviceIn5_8_。 NHibernate:从 tg.vw_State state0_ 中选择 state0_.Id 作为 Id9_,state0_.Name 作为 Name9_,state0_.Abbreviation 作为 Abbrevia3_9_,state0_.CountryId 作为 CountryId9_ NHibernate:从 tg.vw_DeviceGroup devicegrou0_ 中选择 devicegrou0_.Id 作为 Id0_、devicegrou0_.Name 作为 Name0_、devicegrou0_.OldId 作为 OldId0_、devicegrou0_.DeviceGroupTypeId 作为 DeviceGr4_0_、devicegrou0_.SiteId 作为 SiteId0_ NHibernate:从 tg.v_User user0_ 中选择 user0_.Id 作为 Id2_、user0_.Username 作为 Username2_、user0_.Password 作为 Password2_、user0_.FirstName 作为 FirstName2_、user0_.LastName 作为 LastName2_ NHibernate:选择 site0_.Id 作为 Id10_,site0_.Name 作为 Name10_,site0_.Address 作为 Address10_,site0_.City 作为 City10_,site0_.PostalCode 作为 PostalCode10_,site0_.Latitude 作为 Latitude10_,site0_.Longitude 作为 Longitude10_,site0_.PrimaryGroupName 作为 PrimaryG8_10_ ,site0_.SecondaryGroupName 为 Secondar9_10_,site0_.StateId 为来自 tg.v_Site site0_ 的 StateId10_ NHibernate:从 tg.v_Device device0_ 中选择 device0_.Id 作为 Id7_、device0_.DeviceTypeId 作为 DeviceTy2_7_、device0_.Name 作为 Name7_、device0_.NodeId 作为 NodeId7_、device0_.SiteId 作为 SiteId7_ NHibernate:从 tg.vw_BaseConnection Connection0_ 中选择 connection0_.ConnectionId 作为 Connecti1_6_、connection0_.RemoteIP 作为 RemoteIP6_、connection0_.ConnectedOn 作为 Connecte3_6_、connection0_.DisconnectedOn 作为 Disconne4_6_、connection0_.BaseStationId 作为 BaseStat5_6_ NHibernate:从tg.vw_Countrycountry0_中选择country0_.Id作为Id1_,country0_.Name作为Name1_ NHibernate:插入 tg.vw_Country(名称)值(@p0);选择 SCOPE_IDENTITY(); @p0 = '美国' NHibernate:插入 tg.vw_State(名称、缩写、CountryId)值(@p0、@p1、@p2);选择 SCOPE_IDENTITY(); @p0 = '明尼苏达',@p1 = '明尼苏达',@p2 = '347' 休眠状态: NHibernate:插入 tg.vw_Country(名称)值(@p0);选择 SCOPE_IDENTITY(); @p0 = '美国' NHibernate:插入 tg.vw_State(名称、缩写、CountryId)值(@p0、@p1、@p2);选择 SCOPE_IDENTITY(); @p0 = '明尼苏达',@p1 = '明尼苏达',@p2 = '348' 休眠状态: NHibernate:插入 tg.vw_Country(名称)值(@p0);选择 SCOPE_IDENTITY(); @p0 = '美国' NHibernate:插入 tg.vw_Country(名称)值(@p0);选择 SCOPE_IDENTITY(); @p0 = '蹩脚的国家' 休眠状态: NHibernate:插入 tg.v_Site(名称、地址、城市、邮政编码、纬度、经度、PrimaryGroupName、SecondaryGroupName、StateId)值(@p0、@p1、@p2、@p3、@p4、@p5、@p6、@ p7,@p8);选择 SCOPE_IDENTITY(); @p0 = 'abc', @p1 = '12343 测试大道', @p2 = 'wallsite', @p3 = '33333', @p4 = '55', @p5 = '-92.2', @p6 = 'Pri ', @p7 = '秒', @p8 = '181' NHibernate:插入 tg.v_Site(名称、地址、城市、邮政编码、纬度、经度、PrimaryGroupName、SecondaryGroupName、StateId)值(@p0、@p1、@p2、@p3、@p4、@p5、@p6、@ p7,@p8);选择 SCOPE_IDENTITY(); @p0 = '站点墙', @p1 = '12343 测试大道', @p2 = '墙站点', @p3 = '44444', @p4 = '55', @p5 = '-92.2', @p6 = ' Pri',@p7 = '秒',@p8 = '181' NHibernate:插入 tg.v_Site(名称、地址、城市、邮政编码、纬度、经度、PrimaryGroupName、SecondaryGroupName、StateId)值(@p0、@p1、@p2、@p3、@p4、@p5、@p6、@ p7,@p8);选择 SCOPE_IDENTITY(); @p0 = '站点', @p1 = '12343 测试大道', @p2 = '墙站', @p3 = '55555', @p4 = '55', @p5 = '-92.2', @p6 = 'Pri ', @p7 = '秒', @p8 = '180' NHibernate:插入 tg.v_Site(名称、地址、城市、邮政编码、纬度、经度、PrimaryGroupName、SecondaryGroupName、StateId)值(@p0、@p1、@p2、@p3、@p4、@p5、@p6、@ p7,@p8);选择 SCOPE_IDENTITY(); @p0 = '站点墙', @p1 = '12343 测试大道', @p2 = 'walstreet', @p3 = '66666', @p4 = '55', @p5 = '-92.2', @p6 = ' Pri', @p7 = 'Sec', @p8 = '181'
NHibernate: 选择不同的 site.Id 作为 Id10_0_, site.Name 作为 Name10_0_, site.Address 作为 Address10_0_, site.City 作为 City10_0_, site.PostalCode 作为 PostalCode10_0_, site.Latitude 为 Latitude10_0_、site.Longitude 为 Longitude10_0_、site.PrimaryGroupName 为 PrimaryG8_10_0_、site.SecondaryGroupName 为 Secondar9_10_0_、site.StateId 为 StateId10_0_ FROM v_Site 站点 WHERE 站点.Id IN ( 选择 ID 来自 vw_SearchSite 其中包含(vw_SearchSite.*,@p0) ); @p0 = 'abc'
NHibernate:选择 deviceinst0_.Id 作为 Id5_,deviceinst0_.Name 作为 Name5_,deviceinst0_.Latitude 作为 Latitude5_,deviceinst0_.Longitude 作为 Longitude5_,deviceinst0_.InstallationDate 作为 Installa5_5_,deviceinst0_.RemovalDate 作为 RemovalD6_5_,deviceinst0_.DeviceId 作为 DeviceId5_ 、deviceinst0_.PrimaryGroupId 作为 PrimaryG8_5_、deviceinst0_.SecondaryGroupId 作为来自 tg.v_DeviceInstall deviceinst0_ 的 Secondar9_5_ NHibernate:从 tg.vw_BaseStation basestatio0_ 选择 basestatio0_.BaseStationId 作为 BaseStat1_4_、basestatio0_.BaseId 作为 BaseId4_、basestatio0_.InstalledOn 作为 Installe3_4_、basestatio0_.SiteId 作为 SiteId4_ NHibernate:从 tg.v_Threshold Threshold0_ 中选择阈值0_.Id 作为 Id8_、阈值0_.ReadingTypeId 作为 ReadingT2_8_、阈值0_.UpperBound 作为 UpperBound8_、阈值0_.LowerBound 作为 LowerBound8_、阈值0_.DeviceInstallId 作为 DeviceIn5_8_。 NHibernate:从 tg.vw_State state0_ 中选择 state0_.Id 作为 Id9_,state0_.Name 作为 Name9_,state0_.Abbreviation 作为 Abbrevia3_9_,state0_.CountryId 作为 CountryId9_ NHibernate:从 tg.vw_DeviceGroup devicegrou0_ 中选择 devicegrou0_.Id 作为 Id0_、devicegrou0_.Name 作为 Name0_、devicegrou0_.OldId 作为 OldId0_、devicegrou0_.DeviceGroupTypeId 作为 DeviceGr4_0_、devicegrou0_.SiteId 作为 SiteId0_ NHibernate:从 tg.v_User user0_ 中选择 user0_.Id 作为 Id2_、user0_.Username 作为 Username2_、user0_.Password 作为 Password2_、user0_.FirstName 作为 FirstName2_、user0_.LastName 作为 LastName2_ NHibernate:选择 site0_.Id 作为 Id10_,site0_.Name 作为 Name10_,site0_.Address 作为 Address10_,site0_.City 作为 City10_,site0_.PostalCode 作为 PostalCode10_,site0_.Latitude 作为 Latitude10_,site0_.Longitude 作为 Longitude10_,site0_.PrimaryGroupName 作为 PrimaryG8_10_ ,site0_.SecondaryGroupName 为 Secondar9_10_,site0_.StateId 为来自 tg.v_Site site0_ 的 StateId10_ NHibernate:选择 Primarygro0_.SiteId 作为 SiteId1_、primarygro0_.Id 作为 Id1_、primarygro0_.Id 作为 Id0_0_、primarygro0_.Name 作为 Name0_0_、primarygro0_.OldId 作为 OldId0_0_、primarygro0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、primarygro0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup gro0_ 哪里((primarygro0_.DeviceGroupTypeId = 1)) 和primarygro0_.SiteId=@p0; @p0 = '381' NHibernate:选择 secondaryg0_.SiteId 作为 SiteId1_、 secondaryg0_.Id 作为 Id1_、 secondaryg0_.Id 作为 Id0_0_、 secondaryg0_.Name 作为 Name0_0_、 secondaryg0_.OldId 作为 OldId0_0_、 secondaryg0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、 secondaryg0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup secondary g0_ 哪里((secondaryg0_.DeviceGroupTypeId = 2)) 和 secondaryg0_.SiteId=@p0; @p0 = '381' NHibernate:选择 Primarygro0_.SiteId 作为 SiteId1_、primarygro0_.Id 作为 Id1_、primarygro0_.Id 作为 Id0_0_、primarygro0_.Name 作为 Name0_0_、primarygro0_.OldId 作为 OldId0_0_、primarygro0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、primarygro0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup gro0_ 哪里((primarygro0_.DeviceGroupTypeId = 1)) 和primarygro0_.SiteId=@p0; @p0 = '382' NHibernate:选择 secondaryg0_.SiteId 作为 SiteId1_、 secondaryg0_.Id 作为 Id1_、 secondaryg0_.Id 作为 Id0_0_、 secondaryg0_.Name 作为 Name0_0_、 secondaryg0_.OldId 作为 OldId0_0_、 secondaryg0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、 secondaryg0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup secondary g0_ 哪里((secondaryg0_.DeviceGroupTypeId = 2)) 和 secondaryg0_.SiteId=@p0; @p0 = '382' NHibernate:选择 Primarygro0_.SiteId 作为 SiteId1_、primarygro0_.Id 作为 Id1_、primarygro0_.Id 作为 Id0_0_、primarygro0_.Name 作为 Name0_0_、primarygro0_.OldId 作为 OldId0_0_、primarygro0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、primarygro0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup gro0_ 哪里((primarygro0_.DeviceGroupTypeId = 1)) 和primarygro0_.SiteId=@p0; @p0 = '383' NHibernate:选择 secondaryg0_.SiteId 作为 SiteId1_、 secondaryg0_.Id 作为 Id1_、 secondaryg0_.Id 作为 Id0_0_、 secondaryg0_.Name 作为 Name0_0_、 secondaryg0_.OldId 作为 OldId0_0_、 secondaryg0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、 secondaryg0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup secondary g0_ 哪里((secondaryg0_.DeviceGroupTypeId = 2)) 和 secondaryg0_.SiteId=@p0; @p0 = '383' NHibernate:选择 Primarygro0_.SiteId 作为 SiteId1_、primarygro0_.Id 作为 Id1_、primarygro0_.Id 作为 Id0_0_、primarygro0_.Name 作为 Name0_0_、primarygro0_.OldId 作为 OldId0_0_、primarygro0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、primarygro0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup gro0_ 哪里((primarygro0_.DeviceGroupTypeId = 1)) 和primarygro0_.SiteId=@p0; @p0 = '384' NHibernate:选择 secondaryg0_.SiteId 作为 SiteId1_、 secondaryg0_.Id 作为 Id1_、 secondaryg0_.Id 作为 Id0_0_、 secondaryg0_.Name 作为 Name0_0_、 secondaryg0_.OldId 作为 OldId0_0_、 secondaryg0_.DeviceGroupTypeId 作为 DeviceGr4_0_0_、 secondaryg0_.SiteId 作为 SiteId0_0_ FROM tg.vw_DeviceGroup secondary g0_ 哪里((secondaryg0_.DeviceGroupTypeId = 2)) 和 secondaryg0_.SiteId=@p0; @p0 = '384' NHibernate:从 tg.v_Device device0_ 中选择 device0_.Id 作为 Id7_、device0_.DeviceTypeId 作为 DeviceTy2_7_、device0_.Name 作为 Name7_、device0_.NodeId 作为 NodeId7_、device0_.SiteId 作为 SiteId7_ NHibernate:从 tg.vw_BaseConnection Connection0_ 中选择 connection0_.ConnectionId 作为 Connecti1_6_、connection0_.RemoteIP 作为 RemoteIP6_、connection0_.ConnectedOn 作为 Connecte3_6_、connection0_.DisconnectedOn 作为 Disconne4_6_、connection0_.BaseStationId 作为 BaseStat5_6_ NHibernate:从tg.vw_Countrycountry0_中选择country0_.Id作为Id1_,country0_.Name作为Name1_ NHibernate:选择 states0_.CountryId 作为 CountryId1_,states0_.Id 作为 Id1_,states0_.Id 作为 Id9_0_,states0_.Name 作为 Name9_0_,states0_.缩写作为 Abbrevia3_9_0_,states0_.CountryId 作为 CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0 ; @p0 = '347' NHibernate:选择 states0_.CountryId 作为 CountryId1_,states0_.Id 作为 Id1_,states0_.Id 作为 Id9_0_,states0_.Name 作为 Name9_0_,states0_.缩写作为 Abbrevia3_9_0_,states0_.CountryId 作为 CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0 ; @p0 = '348' NHibernate:选择 states0_.CountryId 作为 CountryId1_,states0_.Id 作为 Id1_,states0_.Id 作为 Id9_0_,states0_.Name 作为 Name9_0_,states0_.缩写作为 Abbrevia3_9_0_,states0_.CountryId 作为 CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0 ; @p0 = '349' NHibernate:选择 states0_.CountryId 作为 CountryId1_,states0_.Id 作为 Id1_,states0_.Id 作为 Id9_0_,states0_.Name 作为 Name9_0_,states0_.缩写作为 Abbrevia3_9_0_,states0_.CountryId 作为 CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0 ; @p0 = '350' 休眠状态: 休眠状态: 休眠状态: NHibernate:
System.Data.SqlClient.SqlException:无效的对象名称“v_Site”。
在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection) 在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObject stateObj) 在 System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 在 System.Data.SqlClient.SqlDataReader.get_MetaData() 在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串resetOptionsString) 在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、布尔异步) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、字符串方法、DbAsyncResult 结果) 在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法) 在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior行为,字符串方法) 在System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行为) 在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() 在NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) 在NHibernate.Loader.Loader.GetResultSet(IDbCommand st,布尔autoDiscoverTypes,布尔可调用,RowSelection选择,ISessionImplementor会话) 在NHibernate.Loader.Loader.DoQuery(ISessionImplementor会话,QueryParameters queryParameters,布尔returnProxies) 在NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor会话,QueryParameters queryParameters,布尔returnProxies) 在 NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
NHibernate.ADOException:无法执行查询 [ SELECT DISTINCT site.Id 为 Id10_0_、site.Name 为 Name10_0_、site.Address 为 Address10_0_、site.City 为 City10_0_、site.PostalCode 为 PostalCode10_0_、site.Latitude 为 Latitude10_0_、site.Longitude 为 Longitude10_0_、site.PrimaryGroupName 为 PrimaryG8_10_0_ ,site.SecondaryGroupName 为 Secondar9_10_0_,site.StateId 为 StateId10_0_ FROM v_Site 站点 WHERE 站点.Id IN ( 选择 ID 来自 vw_SearchSite 哪里包含(vw_SearchSite.,?) )] 名称:模式 - 值:abc [SQL:选择不同的 site.Id 作为 Id10_0_、site.Name 作为 Name10_0_、site.Address 作为 Address10_0_、site.City 作为 City10_0_、site.PostalCode 作为 PostalCode10_0_、site.Latitude 作为 Latitude10_0_、site.Longitude 作为 Longitude10_0_、site.PrimaryGroupName为 PrimaryG8_10_0_,site.SecondaryGroupName 为 Secondar9_10_0_,site.StateId 为 StateId10_0_ FROM v_Site 站点 WHERE 站点.Id IN ( 选择 ID 来自 vw_SearchSite 哪里包含(vw_SearchSite.,?) )]
在 NHibernate.Loader.Loader.DoList(ISessionImplementor 会话,QueryParameters queryParameters) 在NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor会话,QueryParameters queryParameters) 在NHibernate.Loader.Loader.List(ISessionImplementor会话,QueryParameters queryParameters,ISet`1 querySpaces,IType [] resultTypes) 在NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor会话,QueryParameters查询参数) 在NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery,QueryParameters queryParameters,IList结果) 在NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification规范,QueryParameters查询参数,IList结果) 在NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification规范,QueryParameters查询参数) 在 NHibernate.Impl.SqlQueryImpl.List() 在 SiteRepository.cs 中的 Toro.TurfGuard.Common.Infrastruct.DataAccess.Impl.SiteRepository.GetSitesforSearch(字符串搜索):第 33 行 在 Toro.TurfGuard.Common.IntegrationTests.Infrastruct.DataAccess.Impl.SiteRepositoryTester.Getsitesforsearch_returns_all_matching_sites_test() in SiteRepositoryTester.cs: line 109
所以,任何人都可以帮助我处理这些异常。感谢立即提供帮助。
I am implementing a full text search using a view vw_SearchSite which has all the searchable fields and returning sites which have site IDs in common with the search results.
the query:
.....
<return alias="site" class="Site"/>
SELECT DISTINCT {site.*}
FROM v_Site {site}
WHERE {site}.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.*,:pattern)
)
the implementation:
public Site[] GetSitesforSearch(string search)
{
using (var session = GetSession())
{
var q1 = session.GetNamedQuery("SearchSite").SetString("pattern", search);
var q2 = q1.List<Site>().ToArray();
return q2;
}
}
the exception when I unit test it:
in expected: {site} [SELECT DISTINCT {site.*}
FROM v_Site {site}
WHERE {site}.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.*,:pattern)
)]
I have full permissions to the localhost database. I tried all permutations and combinations I could with the above code and failed to figure a way out. the query is working absolutely fine when I executed it in SQL SERVER management studio.
This is My Unit Test:
public void Getsitesforsearch_returns_all_matching_sites_test()
{
//Arrange
const string search = "abc";
var country = _entityBuilder.CreateCountry();
country.Name = "wall country";
var country1 = _entityBuilder.CreateCountry();
country.Name = "crappy country";
var state1 = _entityBuilder.CreateState();
state1.Country = country;
var state2 = _entityBuilder.CreateState();
state2.Country = country1;
state1.Name = "wall state";
state1.Abbreviation = "WS";
state2.Name = "crap";
state2.Abbreviation = "CR";
var site1 = _entityBuilder.CreateSite();
var site2 = _entityBuilder.CreateSite();
var site3 = _entityBuilder.CreateSite();
var site4 = _entityBuilder.CreateSite();
site1.Name = "abc";
site1.City = "wallsite";
site1.PostalCode = "33333";
site1.State = state2;
site2.State = state2;
site2.City = "wallsite";
site2.PostalCode = "44444";
site2.Name = "site wall";
site3.State = state1;
site3.City = "wallsite";
site3.PostalCode = "55555";
site3.Name = "site";
site4.City = "walstreet";
site4.PostalCode = "66666";
site4.Name = "site wall";
site4.State = state2;
PersistEntities(state1, state2, country1,country);
PersistEntities(site1,site2,site3,site4);
var sites = new[] {site2,site3,site4};
//Act
var repository = CreateRepository();
var result = repository.GetSitesforSearch(search);
//Assert
result.ShouldNotContain(site1);
result.ShouldEqual(sites) ;
result.ShouldContain(site2);
result.ShouldContain(site3);
result.ShouldContain(site4);
}
This is the error:
SiteRepositoryTester.Getsitesforsearch_returns_all_matching_sites_test : Failed
NHibernate: select deviceinst0_.Id as Id5_, deviceinst0_.Name as Name5_, deviceinst0_.Latitude as Latitude5_, deviceinst0_.Longitude as Longitude5_, deviceinst0_.InstallationDate as Installa5_5_, deviceinst0_.RemovalDate as RemovalD6_5_, deviceinst0_.DeviceId as DeviceId5_, deviceinst0_.PrimaryGroupId as PrimaryG8_5_, deviceinst0_.SecondaryGroupId as Secondar9_5_ from tg.v_DeviceInstall deviceinst0_
NHibernate: select basestatio0_.BaseStationId as BaseStat1_4_, basestatio0_.BaseId as BaseId4_, basestatio0_.InstalledOn as Installe3_4_, basestatio0_.SiteId as SiteId4_ from tg.vw_BaseStation basestatio0_
NHibernate: select threshold0_.Id as Id8_, threshold0_.ReadingTypeId as ReadingT2_8_, threshold0_.UpperBound as UpperBound8_, threshold0_.LowerBound as LowerBound8_, threshold0_.DeviceInstallId as DeviceIn5_8_ from tg.v_Threshold threshold0_
NHibernate: select state0_.Id as Id9_, state0_.Name as Name9_, state0_.Abbreviation as Abbrevia3_9_, state0_.CountryId as CountryId9_ from tg.vw_State state0_
NHibernate: select devicegrou0_.Id as Id0_, devicegrou0_.Name as Name0_, devicegrou0_.OldId as OldId0_, devicegrou0_.DeviceGroupTypeId as DeviceGr4_0_, devicegrou0_.SiteId as SiteId0_ from tg.vw_DeviceGroup devicegrou0_
NHibernate: select user0_.Id as Id2_, user0_.Username as Username2_, user0_.Password as Password2_, user0_.FirstName as FirstName2_, user0_.LastName as LastName2_ from tg.v_User user0_
NHibernate: select site0_.Id as Id10_, site0_.Name as Name10_, site0_.Address as Address10_, site0_.City as City10_, site0_.PostalCode as PostalCode10_, site0_.Latitude as Latitude10_, site0_.Longitude as Longitude10_, site0_.PrimaryGroupName as PrimaryG8_10_, site0_.SecondaryGroupName as Secondar9_10_, site0_.StateId as StateId10_ from tg.v_Site site0_
NHibernate: select device0_.Id as Id7_, device0_.DeviceTypeId as DeviceTy2_7_, device0_.Name as Name7_, device0_.NodeId as NodeId7_, device0_.SiteId as SiteId7_ from tg.v_Device device0_
NHibernate: select connection0_.ConnectionId as Connecti1_6_, connection0_.RemoteIP as RemoteIP6_, connection0_.ConnectedOn as Connecte3_6_, connection0_.DisconnectedOn as Disconne4_6_, connection0_.BaseStationId as BaseStat5_6_ from tg.vw_BaseConnection connection0_
NHibernate: select country0_.Id as Id1_, country0_.Name as Name1_ from tg.vw_Country country0_
NHibernate: INSERT INTO tg.vw_Country (Name) VALUES (@p0); select SCOPE_IDENTITY(); @p0 = 'United States'
NHibernate: INSERT INTO tg.vw_State (Name, Abbreviation, CountryId) VALUES (@p0, @p1, @p2); select SCOPE_IDENTITY(); @p0 = 'Minnesota', @p1 = 'MN', @p2 = '347'
NHibernate:
NHibernate: INSERT INTO tg.vw_Country (Name) VALUES (@p0); select SCOPE_IDENTITY(); @p0 = 'United States'
NHibernate: INSERT INTO tg.vw_State (Name, Abbreviation, CountryId) VALUES (@p0, @p1, @p2); select SCOPE_IDENTITY(); @p0 = 'Minnesota', @p1 = 'MN', @p2 = '348'
NHibernate:
NHibernate: INSERT INTO tg.vw_Country (Name) VALUES (@p0); select SCOPE_IDENTITY(); @p0 = 'United States'
NHibernate: INSERT INTO tg.vw_Country (Name) VALUES (@p0); select SCOPE_IDENTITY(); @p0 = 'crappy country'
NHibernate:
NHibernate: INSERT INTO tg.v_Site (Name, Address, City, PostalCode, Latitude, Longitude, PrimaryGroupName, SecondaryGroupName, StateId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8); select SCOPE_IDENTITY(); @p0 = 'abc', @p1 = '12343 Testing Blvd', @p2 = 'wallsite', @p3 = '33333', @p4 = '55', @p5 = '-92.2', @p6 = 'Pri', @p7 = 'Sec', @p8 = '181'
NHibernate: INSERT INTO tg.v_Site (Name, Address, City, PostalCode, Latitude, Longitude, PrimaryGroupName, SecondaryGroupName, StateId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8); select SCOPE_IDENTITY(); @p0 = 'site wall', @p1 = '12343 Testing Blvd', @p2 = 'wallsite', @p3 = '44444', @p4 = '55', @p5 = '-92.2', @p6 = 'Pri', @p7 = 'Sec', @p8 = '181'
NHibernate: INSERT INTO tg.v_Site (Name, Address, City, PostalCode, Latitude, Longitude, PrimaryGroupName, SecondaryGroupName, StateId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8); select SCOPE_IDENTITY(); @p0 = 'site', @p1 = '12343 Testing Blvd', @p2 = 'wallsite', @p3 = '55555', @p4 = '55', @p5 = '-92.2', @p6 = 'Pri', @p7 = 'Sec', @p8 = '180'
NHibernate: INSERT INTO tg.v_Site (Name, Address, City, PostalCode, Latitude, Longitude, PrimaryGroupName, SecondaryGroupName, StateId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8); select SCOPE_IDENTITY(); @p0 = 'site wall', @p1 = '12343 Testing Blvd', @p2 = 'walstreet', @p3 = '66666', @p4 = '55', @p5 = '-92.2', @p6 = 'Pri', @p7 = 'Sec', @p8 = '181'
NHibernate: SELECT DISTINCT site.Id as Id10_0_, site.Name as Name10_0_, site.Address as Address10_0_, site.City as City10_0_, site.PostalCode as PostalCode10_0_, site.Latitude as Latitude10_0_, site.Longitude as Longitude10_0_, site.PrimaryGroupName as PrimaryG8_10_0_, site.SecondaryGroupName as Secondar9_10_0_, site.StateId as StateId10_0_
FROM v_Site site
WHERE site.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.*,@p0)
); @p0 = 'abc'
NHibernate: select deviceinst0_.Id as Id5_, deviceinst0_.Name as Name5_, deviceinst0_.Latitude as Latitude5_, deviceinst0_.Longitude as Longitude5_, deviceinst0_.InstallationDate as Installa5_5_, deviceinst0_.RemovalDate as RemovalD6_5_, deviceinst0_.DeviceId as DeviceId5_, deviceinst0_.PrimaryGroupId as PrimaryG8_5_, deviceinst0_.SecondaryGroupId as Secondar9_5_ from tg.v_DeviceInstall deviceinst0_
NHibernate: select basestatio0_.BaseStationId as BaseStat1_4_, basestatio0_.BaseId as BaseId4_, basestatio0_.InstalledOn as Installe3_4_, basestatio0_.SiteId as SiteId4_ from tg.vw_BaseStation basestatio0_
NHibernate: select threshold0_.Id as Id8_, threshold0_.ReadingTypeId as ReadingT2_8_, threshold0_.UpperBound as UpperBound8_, threshold0_.LowerBound as LowerBound8_, threshold0_.DeviceInstallId as DeviceIn5_8_ from tg.v_Threshold threshold0_
NHibernate: select state0_.Id as Id9_, state0_.Name as Name9_, state0_.Abbreviation as Abbrevia3_9_, state0_.CountryId as CountryId9_ from tg.vw_State state0_
NHibernate: select devicegrou0_.Id as Id0_, devicegrou0_.Name as Name0_, devicegrou0_.OldId as OldId0_, devicegrou0_.DeviceGroupTypeId as DeviceGr4_0_, devicegrou0_.SiteId as SiteId0_ from tg.vw_DeviceGroup devicegrou0_
NHibernate: select user0_.Id as Id2_, user0_.Username as Username2_, user0_.Password as Password2_, user0_.FirstName as FirstName2_, user0_.LastName as LastName2_ from tg.v_User user0_
NHibernate: select site0_.Id as Id10_, site0_.Name as Name10_, site0_.Address as Address10_, site0_.City as City10_, site0_.PostalCode as PostalCode10_, site0_.Latitude as Latitude10_, site0_.Longitude as Longitude10_, site0_.PrimaryGroupName as PrimaryG8_10_, site0_.SecondaryGroupName as Secondar9_10_, site0_.StateId as StateId10_ from tg.v_Site site0_
NHibernate: SELECT primarygro0_.SiteId as SiteId1_, primarygro0_.Id as Id1_, primarygro0_.Id as Id0_0_, primarygro0_.Name as Name0_0_, primarygro0_.OldId as OldId0_0_, primarygro0_.DeviceGroupTypeId as DeviceGr4_0_0_, primarygro0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup primarygro0_ WHERE ((primarygro0_.DeviceGroupTypeId = 1)) and primarygro0_.SiteId=@p0; @p0 = '381'
NHibernate: SELECT secondaryg0_.SiteId as SiteId1_, secondaryg0_.Id as Id1_, secondaryg0_.Id as Id0_0_, secondaryg0_.Name as Name0_0_, secondaryg0_.OldId as OldId0_0_, secondaryg0_.DeviceGroupTypeId as DeviceGr4_0_0_, secondaryg0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup secondaryg0_ WHERE ((secondaryg0_.DeviceGroupTypeId = 2)) and secondaryg0_.SiteId=@p0; @p0 = '381'
NHibernate: SELECT primarygro0_.SiteId as SiteId1_, primarygro0_.Id as Id1_, primarygro0_.Id as Id0_0_, primarygro0_.Name as Name0_0_, primarygro0_.OldId as OldId0_0_, primarygro0_.DeviceGroupTypeId as DeviceGr4_0_0_, primarygro0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup primarygro0_ WHERE ((primarygro0_.DeviceGroupTypeId = 1)) and primarygro0_.SiteId=@p0; @p0 = '382'
NHibernate: SELECT secondaryg0_.SiteId as SiteId1_, secondaryg0_.Id as Id1_, secondaryg0_.Id as Id0_0_, secondaryg0_.Name as Name0_0_, secondaryg0_.OldId as OldId0_0_, secondaryg0_.DeviceGroupTypeId as DeviceGr4_0_0_, secondaryg0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup secondaryg0_ WHERE ((secondaryg0_.DeviceGroupTypeId = 2)) and secondaryg0_.SiteId=@p0; @p0 = '382'
NHibernate: SELECT primarygro0_.SiteId as SiteId1_, primarygro0_.Id as Id1_, primarygro0_.Id as Id0_0_, primarygro0_.Name as Name0_0_, primarygro0_.OldId as OldId0_0_, primarygro0_.DeviceGroupTypeId as DeviceGr4_0_0_, primarygro0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup primarygro0_ WHERE ((primarygro0_.DeviceGroupTypeId = 1)) and primarygro0_.SiteId=@p0; @p0 = '383'
NHibernate: SELECT secondaryg0_.SiteId as SiteId1_, secondaryg0_.Id as Id1_, secondaryg0_.Id as Id0_0_, secondaryg0_.Name as Name0_0_, secondaryg0_.OldId as OldId0_0_, secondaryg0_.DeviceGroupTypeId as DeviceGr4_0_0_, secondaryg0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup secondaryg0_ WHERE ((secondaryg0_.DeviceGroupTypeId = 2)) and secondaryg0_.SiteId=@p0; @p0 = '383'
NHibernate: SELECT primarygro0_.SiteId as SiteId1_, primarygro0_.Id as Id1_, primarygro0_.Id as Id0_0_, primarygro0_.Name as Name0_0_, primarygro0_.OldId as OldId0_0_, primarygro0_.DeviceGroupTypeId as DeviceGr4_0_0_, primarygro0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup primarygro0_ WHERE ((primarygro0_.DeviceGroupTypeId = 1)) and primarygro0_.SiteId=@p0; @p0 = '384'
NHibernate: SELECT secondaryg0_.SiteId as SiteId1_, secondaryg0_.Id as Id1_, secondaryg0_.Id as Id0_0_, secondaryg0_.Name as Name0_0_, secondaryg0_.OldId as OldId0_0_, secondaryg0_.DeviceGroupTypeId as DeviceGr4_0_0_, secondaryg0_.SiteId as SiteId0_0_ FROM tg.vw_DeviceGroup secondaryg0_ WHERE ((secondaryg0_.DeviceGroupTypeId = 2)) and secondaryg0_.SiteId=@p0; @p0 = '384'
NHibernate: select device0_.Id as Id7_, device0_.DeviceTypeId as DeviceTy2_7_, device0_.Name as Name7_, device0_.NodeId as NodeId7_, device0_.SiteId as SiteId7_ from tg.v_Device device0_
NHibernate: select connection0_.ConnectionId as Connecti1_6_, connection0_.RemoteIP as RemoteIP6_, connection0_.ConnectedOn as Connecte3_6_, connection0_.DisconnectedOn as Disconne4_6_, connection0_.BaseStationId as BaseStat5_6_ from tg.vw_BaseConnection connection0_
NHibernate: select country0_.Id as Id1_, country0_.Name as Name1_ from tg.vw_Country country0_
NHibernate: SELECT states0_.CountryId as CountryId1_, states0_.Id as Id1_, states0_.Id as Id9_0_, states0_.Name as Name9_0_, states0_.Abbreviation as Abbrevia3_9_0_, states0_.CountryId as CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0; @p0 = '347'
NHibernate: SELECT states0_.CountryId as CountryId1_, states0_.Id as Id1_, states0_.Id as Id9_0_, states0_.Name as Name9_0_, states0_.Abbreviation as Abbrevia3_9_0_, states0_.CountryId as CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0; @p0 = '348'
NHibernate: SELECT states0_.CountryId as CountryId1_, states0_.Id as Id1_, states0_.Id as Id9_0_, states0_.Name as Name9_0_, states0_.Abbreviation as Abbrevia3_9_0_, states0_.CountryId as CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0; @p0 = '349'
NHibernate: SELECT states0_.CountryId as CountryId1_, states0_.Id as Id1_, states0_.Id as Id9_0_, states0_.Name as Name9_0_, states0_.Abbreviation as Abbrevia3_9_0_, states0_.CountryId as CountryId9_0_ FROM tg.vw_State states0_ WHERE states0_.CountryId=@p0; @p0 = '350'
NHibernate:
NHibernate:
NHibernate:
NHibernate:
System.Data.SqlClient.SqlException: Invalid object name 'v_Site'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
NHibernate.ADOException: could not execute query
[ SELECT DISTINCT site.Id as Id10_0_, site.Name as Name10_0_, site.Address as Address10_0_, site.City as City10_0_, site.PostalCode as PostalCode10_0_, site.Latitude as Latitude10_0_, site.Longitude as Longitude10_0_, site.PrimaryGroupName as PrimaryG8_10_0_, site.SecondaryGroupName as Secondar9_10_0_, site.StateId as StateId10_0_
FROM v_Site site
WHERE site.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.,?)
) ]
Name:pattern - Value:abc
[SQL: SELECT DISTINCT site.Id as Id10_0_, site.Name as Name10_0_, site.Address as Address10_0_, site.City as City10_0_, site.PostalCode as PostalCode10_0_, site.Latitude as Latitude10_0_, site.Longitude as Longitude10_0_, site.PrimaryGroupName as PrimaryG8_10_0_, site.SecondaryGroupName as Secondar9_10_0_, site.StateId as StateId10_0_
FROM v_Site site
WHERE site.Id IN (
SELECT Id
FROM vw_SearchSite
WHERE CONTAINS(vw_SearchSite.,?)
)]
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.List()
at Toro.TurfGuard.Common.Infrastructure.DataAccess.Impl.SiteRepository.GetSitesforSearch(String search) in SiteRepository.cs: line 33
at Toro.TurfGuard.Common.IntegrationTests.Infrastructure.DataAccess.Impl.SiteRepositoryTester.Getsitesforsearch_returns_all_matching_sites_test() in SiteRepositoryTester.cs: line 109
So, could anyone help me with handling these exceptions. immediate help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表名称
v_Site
是否正确?Is the table name,
v_Site
, correct?