Nhibernate - lists on SelectList

浪子不回头ぞ 提交于 2020-01-02 23:16:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!