流利的nHibernate:错误'在字段中有一个引用“,”但它没有定义'

时间:2015-02-13 14:17:07

标签: fluent-nhibernate fluent-nhibernate-mapping

这是表格架构

  

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

映射

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();
    }
}

然后我想执行该代码:

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();

我收到错误消息:

  

到变量“x”类型“myProject.UserMessage”有一个引用   在字段“,”但它没有定义

出了什么问题?

1 个答案:

答案 0 :(得分:1)

您无法在QueryOver中执行要求执行的查询。如果您想要做类似的事情,那么您将使用NHibernate Linq提供程序:

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()是上面的关键