简体   繁体   English

具有外键关系的流利的NHibernate映射

[英]Fluent NHibernate Mapping with foreign key relationship

Here is my fluent map for Drops Table 这是我对Drops Table的流利地图

this.Table("Drops");
this.LazyLoad();
this.Id(x => x.Guid).GeneratedBy.Guid().Column("Guid");
this.References(x => x.User).column("UserGuid");
this.Map(x => x.FromLocation).Column("FromLocation").Not.Nullable().Length(50);
this.Map(x => x.ToLocation).Column("ToLocation").Not.Nullable().Length(50);
this.Map(x => x.Time).Column("Time").Not.Nullable();

Here is my user Table 这是我的用户表

this.Table("Users");
this.LazyLoad();
this.Id(x => x.Guid).GeneratedBy.Guid();
this.Map(x => x.SessionId).Unique().Column("SessionId");
this.Map(x => x.UserName).Unique().Column("UserName");
this.Map(x => x.Password).Column("Password");
this.Map(x => x.NickName).Column("NickName");
this.Map(x => x.FirstName).Column("FirstName");
this.Map(x => x.LastName).Column("LastName");
this.Map(x => x.Gender).Column("Gender");

So, Drops included User table, 因此,Drops包含了User表,

When I add the drop table, It will added correctly. 当我添加放置表时,它将正确添加。

What I need is, I need to get the list of drop objects using user SessionId. 我需要的是,我需要使用用户SessionId获取放置对象的列表。

I am using below code to get drop collection, 我正在使用以下代码来获取投递集合,

session.QueryOver<Drop>().Where(d => d.UserGuid != user.Guid).List();

but I am getting below error, 但是我遇到了错误,

could not resolve property: UserGuid of: *********.**********.BusinessObjects.Drop 无法解析属性:UserGuid,为:*********。**********。BusinessObjects.Drop

I checked the drop table, UserGuid Column is added 我检查了放置表,添加了UserGuid Column

在此处输入图片说明

How to get the drop list or whats the problem there? 如何获取下拉列表或那里出了什么问题?

Thanks, 谢谢,

Shouldn't it be: 不应该是:

session.QueryOver<Drop>().Where(d => d.User.SessionId != user.SessionId).List();

if you are looking up by user session id (or excluding them in your case). 如果您要通过用户会话ID查找(或在您的情况下排除它们)。

EDIT 编辑

Sorry, I got so hung up on the initial point that I missed the fact that you need to define an alias for the user object. 抱歉,我对初始点很挂念,以至于错过了需要为用户对象定义别名的事实。 Try: 尝试:

User alias = null;
session.QueryOver<Drop>().JoinAlias(d=>d.User,()=>alias).Where(d => alias.SessionId != user.SessionId).List();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM