Tony
Tony

Reputation: 12695

Fluent nHibernate: error 'there is a reference in the field "," but it is not defined'

here's the table schema

UserLogin 1---* UserMessages 1---* UserMessagesReceiver

mappings

public class UserLoginMap : ClassMap<UserLogin>
{
    public UserLoginMap()
    {
        Table("UserLogin");
        Id(x => x.Id).GeneratedBy.Assigned();

        HasMany(x => x.UserMessages).KeyColumn("UserLogin_id").LazyLoad().Cascade.DeleteOrphan().Inverse();
        HasMany(x => x.UserMessagesReceivers).KeyColumn("UserLogin_id").LazyLoad().Cascade.DeleteOrphan().Inverse();
    }
}
public class UserMessageMap : ClassMap<UserMessage>
{
    public UserMessageMap()
    {
        Table("UserMessages");
        Id(x => x.Id).Column("Id");

        References(e => e.UserLogin, "UserLogin_id").Not.LazyLoad();
        HasMany(x => x.UserMessagesReceivers).KeyColumn("UserMessages_id").LazyLoad().Cascade.DeleteOrphan().Inverse();
    }
}
public class UserMessagesReceiverMap : ClassMap<UserMessagesReceiver>
{
    public UserMessagesReceiverMap()
    {
        Table("UserMessagesReceiver");
        Id(x => x.Id).GeneratedBy.Assigned();

        References(e => e.UserLogin, "UserLogin_id").Not.LazyLoad();
        References(e => e.UserMessage, "UserMessages_id").Not.LazyLoad();
    }
}

then I want to execute that code:

var result = session.QueryOver<UserMessage>()
                    .Where(x => x.UserLogin.Id == 1 //he's the message sender
                                ||
                                x.UserMessagesReceivers.Count(y => y.UserLogin.Id == 1) > 0) //he's the one of the message receivers
                    .List();

and I get the error message:

to the variable "x" type "myProject.UserMessage" there is a reference in the field "," but it is not defined

what's wrong ?

Upvotes: 0

Views: 80

Answers (1)

Cole W
Cole W

Reputation: 15303

You can't do the kinds of queries you are asking to do in QueryOver. If you want to do something like that you would be using the NHibernate Linq provider instead:

var result = session.Query<UserMessage>()
                    .Where(x => x.UserLogin.Id == 1 ||
                                x.UserMessagesReceivers.Count(y => y.UserLogin.Id == 1) > 0) //he's the one of the message receivers
                    .List();

.Query() is the key above

Upvotes: 1

Related Questions