亚音速 2.1:我疯了吗?
我正在开发一个使用亚音速 2.1 的项目。对于简单的搜索查询,我有以下代码:
DAL.ItemCollection coll = new DAL.ItemCollection();
SubSonic.Select s = new SubSonic.Select();
s.From(DAL.Item.Schema);
s.Where("Title").Like("%" + q + "%").Or("Tags").Like("%" + q + "%").And("IsActive").IsEqualTo(true);
if (fid > 0)
{
s.And("CategoryID").IsEqualTo(fid);
Session["TotalSearchResults"] = null;
}
s.Top(maxitems);
//We'll get the recordcount before paged results
total = s.GetRecordCount();
s.Paged(pageindex, pagesize);
s.OrderDesc("Hits");
s.OrderDesc("Points");
s.OrderDesc("NumberOfVotes");
coll = s.ExecuteAsCollection<DAL.ItemCollection>();
现在的问题是,当我的 fid (FilterId) 大于 0 时,CategoryID 过滤器不起作用。它到达断点没有问题,但它没有被过滤。它与 LIKE 查询有关吗?如果我删除 if 部分和当前 s.where 并更改查询,它会完美地工作:
s.Where("CategoryID").IsEqualTo(fid);
我在这里错过了一些重要的东西吗?
亲切的问候, 标记
Im working on a project using subsonic 2.1. For a simple search query i've the following code:
DAL.ItemCollection coll = new DAL.ItemCollection();
SubSonic.Select s = new SubSonic.Select();
s.From(DAL.Item.Schema);
s.Where("Title").Like("%" + q + "%").Or("Tags").Like("%" + q + "%").And("IsActive").IsEqualTo(true);
if (fid > 0)
{
s.And("CategoryID").IsEqualTo(fid);
Session["TotalSearchResults"] = null;
}
s.Top(maxitems);
//We'll get the recordcount before paged results
total = s.GetRecordCount();
s.Paged(pageindex, pagesize);
s.OrderDesc("Hits");
s.OrderDesc("Points");
s.OrderDesc("NumberOfVotes");
coll = s.ExecuteAsCollection<DAL.ItemCollection>();
Now the thing is, when my fid (FilterId) is larger then 0, the CategoryID filter does not work. It hits the breakpoint no problem but it's not getting filtered. Does it have something do do with the LIKE query? It works perfectly if i remove the if part and current s.where and change the query do this:
s.Where("CategoryID").IsEqualTo(fid);
Do I miss something important here?
Kind regards,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在查询:
但您想要的是:
您可以使用 AndExpression/OrExpression 语法后跟 CloseExpression 获得亚音速 2.1 中的括号。
It looks like you are querying:
but want you want is:
You can get brackets in subsonic 2.1 with the AndExpression/OrExpression syntax follwed by CloseExpression.
自从我使用 2.1 以来已经有一段时间了,但我希望以下内容能够工作:
It's been a while since I've used 2.1 but I would expect the following to work: