Domanda

Here is my fluent map for 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,

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.

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

I checked the drop table, UserGuid Column is added

enter image description here

How to get the drop list or whats the problem there?

Thanks,

È stato utile?

Soluzione

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).

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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top