问题
I'm using NHibernate and I have come across a problem.
I have this entities in my project: Client:
public class Client
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string UserName { get; set; }
public virtual string Password { get; set; }
public virtual IList<Date> Dates { get; set; }
public Client()
{
Dates = new List<Date>();
}
}
Date:
public class Date
{
public virtual int Id { get; set; }
public virtual DateTime DateTime { get; set; }
public virtual Client Client { get; set; }
public virtual int IsVisible { get; set; }
}
And I want to fetch for each client, it's id, name and list of dates, and for each date in that list I want to fetch only the id and the date.
so I tried the following:
Date dateAlias = null;
var list = _session.QueryOver<Client>()
.JoinAlias(x => x.Dates, () => dateAlias)
.SelectList(lst => lst
.Select(x => x.Id)
.Select(x => x.Name)
.Select(() => dateAlias))
.List<object[]>();
and this:
Date dateAlias = null;
var list = _session.QueryOver<Client>()
.JoinAlias(x => x.Dates, () => dateAlias)
.SelectList(lst => lst
.Select(x => x.Id)
.Select(x => x.Name)
.Select(() => dateAlias))
.List<object[]>();
But the result is empty. What am I doing wrong here? and is what I want possible?
回答1:
You can try this query, it may be help to you.
IList<Client> clientData = _session.QueryOver<Client>()
.JoinQueryOver(x => x.Dates)
.Where(x => x.Id && x => x.Name)).List();
来源:https://stackoverflow.com/questions/38821120/nhibernate-lists-on-selectlist