nHibernate Criteria Query 中的数学运算
我在使用 nHibernate 查询时遇到问题。
我有一个存储车辆信息的数据库,用户可以通过品牌、型号、类型和生产日期搜索数据库。
品牌、型号和类型搜索很好,效果很好,这是我遇到的问题的生产日期。所以这里...
日期存储为整数(StartMonth、StartYear、FinishMonth、FinishYear),当最终用户选择日期时,它会作为整数传递给查询,例如 2010006 (2010 * 100 + 6)。
以下是我正在使用的查询的一部分,仅供参考,我正在使用 Lambda 扩展。
if (_searchCriteria.ProductionStart > 0)
{
query.Add<Engine>(e => ((e.StartYear * 100) + e.StartMonth) >= _searchCriteria.ProductionStart);
}
if (_searchCriteria.ProductionEnd > 0)
{
query.Add<Engine>(e => ((e.FinishYear * 100) + e.FinishMonth) <= _searchCriteria.ProductionEnd);
}
但是当查询运行时我收到以下消息,
无法从 ((e.StartYear * 100) + e.StartMonth) 确定成员
任何帮助都会很棒,
问候
Rich
I am having troubles with a nHibernate query.
I have a db which stores vehicle info, and the user is able to search the db by make, model, type and production dates.
Make, model & type search is fine, works a treat, it is the productions dates I am having issues with. So here goes...
The dates are stored as ints (StartMonth, StartYear, FinishMonth, FinishYear), when the end-user selects a date it is passed to the query as an int eg 2010006 (2010 * 100 + 6).
below is part of the query I am using, FYI I am using Lambda Extensions.
if (_searchCriteria.ProductionStart > 0)
{
query.Add<Engine>(e => ((e.StartYear * 100) + e.StartMonth) >= _searchCriteria.ProductionStart);
}
if (_searchCriteria.ProductionEnd > 0)
{
query.Add<Engine>(e => ((e.FinishYear * 100) + e.FinishMonth) <= _searchCriteria.ProductionEnd);
}
But when the query runs I get the following message,
Could not determine member from ((e.StartYear * 100) + e.StartMonth)
Any help would be great,
Regards
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太了解这些 linq 扩展,但我假设您需要在操作之前传递成员名称。
要么年份必须更大,要么年份至少相等且月份更大。这同样适用于低于的 ProductionEnd。
我不确定 lambda 扩展是否支持这样的“或”(
||
) 运算符,但“或”肯定有可能。来自理查兹的评论:
I don't know these linq extensions very well, but I assume that you need to pass the member name before the operation.
Either the year must be greater or the year is at least equal and the month is greater. The same applies to ProductionEnd with lower than.
I'm not sure if the lambda extensions support "or" (
||
) operator like this, but there is surely a possibility for "or".From Richards comment:
@Stefan,我尝试了以下操作,
我使用不同的 AND / OR 组合检查结果(即 ((a && b ) || a) 和 (a || (a && b)) )并弹出几条记录。
经过进一步思考,我得到以下结果,
其中
StartDate
和FinishDate
是表中的计算列和实体的属性。当我们的导师下周回来时我可能会编辑这个。
感谢和问候
富有的
@Stefan, I have tried the following,
I check the results with the different AND / OR combinations (i.e. ((a && b ) || a) and (a || (a && b)) ) and a couple of records pop through.
After some further thought I have the following,
Where
StartDate
andFinishDate
are computed columns in my table and properties on my entity.I may edit this when our guru returns next week.
Thanks and Regards
Rich