NHibernate Criteria 留下反连接/子查询混乱

发布于 2024-12-14 20:07:43 字数 539 浏览 5 评论 0原文

我将用 NHibernate 远远超出我的舒适区这一事实作为序言,因此这可能比我想象的要简单得多。

我有一个 users 表和一个映射到 userevent 对象的 events 表。

我的 event 对象引用单个 user 对象。

我有一个属性,我将其保留在 LastActivityTimeStampuser 对象上。

我的 event 对象上有与 EventTypeSuccess 相关的属性。

要确定“在线”用户列表,我需要收集 LastActivityTimeStamp 大于先前计算的 cutoff 值的所有用户对象,其最后一次活动位于 < code>events 表不是成功的“注销”事件类型。

我该如何写这个标准?

I'll preface this with the fact that NHibernate is well out of my comfort zone, so this may be much simpler than I'm making it out to be.

I have a users table and an events table mapped to user and event objects.

My event objects reference a singular user object.

I have a property that I persist on my user object for LastActivityTimeStamp.

I have properties on my event object related to EventType and Success.

To determine a list of users that are "online", I need to collect all user objects with a LastActivityTimeStamp greater than a previously calculated cutoff value, whose last activity in the events table was not a successful "Logoff" event type.

How would I write this criteria?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城孤痞 2024-12-21 20:07:43

尝试调整这个

var subquery = DetachedCriteria.For<Event>()
    .Add(Restrictions.Eq("Success", true))
    .Add(Restrictions.EqProperty("User.Id", "u.id"))
    .AddOrder(Order.Desc("TimeStamp"))
    .SetProjection(Projections.Property("EventType"))
    .SetMaxResults(1);

session.CreateCriteria<User>("u")
    .Add(Restrictions.Ge("LastActivityTimeStamp", cutoff))
    .Add(Subqueries.Ne(EventType.LogOff, subquery));

try to tweak this

var subquery = DetachedCriteria.For<Event>()
    .Add(Restrictions.Eq("Success", true))
    .Add(Restrictions.EqProperty("User.Id", "u.id"))
    .AddOrder(Order.Desc("TimeStamp"))
    .SetProjection(Projections.Property("EventType"))
    .SetMaxResults(1);

session.CreateCriteria<User>("u")
    .Add(Restrictions.Ge("LastActivityTimeStamp", cutoff))
    .Add(Subqueries.Ne(EventType.LogOff, subquery));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文