1
我在构建标准对象时遇到了一些麻烦。通常情况下,我同样建立我cruteria这样:将“ands”和“ors”组合起来的标准表达式
ISession session = GetSession();
ICriteria criteria = session.CreateCriteria(typeof(MyObject))
.Add(Expression.Gt("StartDate", DateTime.Now.ToUniversalTime()))
.Add(Expression.Eq("SubObject.SubObjectId", subObjectId))
.AddOrder(new Order("StartDate", true));
我需要做的就是创建这样的标准大致如下:
WHERE((a.EndDate IS NOT NULL和 一.EndDate> ='{Now}')OR a.EndDate is NULL)AND((a.SubObject IS NOT NULL AND a.SubObject.SubObjectId ='{Id}') OR a.SubObject IS NULL)AND开始日期< ='{Now}'
是的,我知道我可以使用HQL,但如果可能的话,我想使用Critera来代替。
子对象和enddate可以为空,如果它们为空我想将它们包含在选择中,但如果它们不为null,则需要将它们与值进行比较。子对象的id如果不为null,则当前时间如果enddate不为null。
我知道我需要对“OR”进行析取,但我不确定它们的位置和顺序,只要符合标准。