Query challenge

14 views
Skip to first unread message

Vadimmer

unread,
Nov 21, 2009, 10:10:09 AM11/21/09
to nhusers
Model:

class Message
{
User Author { get; set; }
string Text { get; set; }
}

class MessageReading
{
User ReadBy { get; set; }
Message Message { get; set; }
public bool IsRead { get; set; }
}

The MessageReading table has only ReadBy and Message columns.
Existence of a record means the message was read by specific user.
Absence of a record means the message wasn't read by the given user.

Given a user, for each message object in the db I'd like to get a
MessageReading object with the IsRead property correctly set.

How do I perform this query with NH?

If the question seems unclear, please ask :)

Vadimmer

unread,
Nov 23, 2009, 11:43:57 AM11/23/09
to nhusers
Tried the following HQL and got the following exception.

NHibernate.QueryException : No data type for node: IdentNode mr
[SELECT msg, mr
FROM Model.Message msg
WHERE msg.Contest = :contest
LEFT OUTER JOIN MessageReading mr ON (mr.Message = msg AND mr.User
= :user)]

Is this style of joins supported? Is there any way to do this type of
join (to an unassociated entity)?
Reply all
Reply to author
Forward
0 new messages