我有一个搜索方法如下。我希望在不同表的某些列上分割和搜索用户搜索文本。
string[] searchedTexts = null;
if(searchText!=null)
searchedTexts = searchText.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
WebsitePage page = null;
Account account = null;
AccountLogin login = null;
Author author = null;
var query = Session.QueryOver<WebsitePage>(() => page).Where(() => page.Status == WebsitePageStatus.Online).Left
.JoinQueryOver<Author>(x => x.Blogger, () => author).Left
.JoinQueryOver<Account>(x => x.AccountInfo, () => account).Left
.JoinQueryOver<AccountLogin>(x => x.Logins, () => login);
if (searchedTexts != null)
{
var disconjaction = Expression.Disjunction();
foreach (var text in searchedTexts)
{
disconjaction.Add(Expression.Like(Projections.Property(() => page.Title), text, MatchMode.Anywhere));
disconjaction.Add(Expression.Like(Projections.Property(() => page.Body), text, MatchMode.Anywhere));
disconjaction.Add(Expression.Like(Projections.Property(() => page.TagCommaSeperated), text, MatchMode.Anywhere));
disconjaction.Add(Expression.Like(Projections.Property(() => account.FirstName), text, MatchMode.Anywhere));
disconjaction.Add(Expression.Like(Projections.Property(() => account.LastName), text, MatchMode.Anywhere));
disconjaction.Add(Expression.Like(Projections.Property<AccountLogin>(x => x.UserName), text, MatchMode.Anywhere));
}
query.And(disconjaction);
}
return query.List();
正如您在Expression.Like()方法中看到的,我使用了相同的参数。执行后,nhibernate为每个“Like”表达式添加不同的参数,如:
@p1=N'%test%',@p2=N'%test%',@p3=N'%test%',@p4=N'%search%',@p5=N'%search%',@p6=N'%search%'
在foreach的每个循环中,我想使用一个带有所有6个“Like”表达式的sql参数。 可能吗 ?
答案 0 :(得分:0)
不,这是不可能的。
我认为这也不重要,除非你有兴趣避免TSQL中2100参数的硬限制。