Ako
Ako

Reputation: 93

QueryOver in NHibernate

I'm lost when it comes to to QueryOver in NHibernate, I'm trying to query over a database and retrive 4 values of importans, the rest are unnecessary and take up processing power.

I'm trying this:

var ext = _session.QueryOver<ExternServiceSettings>()
          .Where(x => x.ExternService == ExternServiceEnum.Outlook).List();

which works fine but takes too long and returns everything in the database. then I tried:

    var ext = _session.QueryOver<ExternServiceSettings>()
                  .Where(x => x.ExternService == ExternServiceEnum.Outlook)
                  .List<ExternServiceSettings>()
                  .Select(y => y.UserName);

However this only return the username and won't let me fetch more than one value...

All help is appreciated!

Upvotes: 2

Views: 90

Answers (1)

Radim K&#246;hler
Radim K&#246;hler

Reputation: 123901

We should use .SelectList()

Check the example from doc:

var selection =
    session.QueryOver<Cat>()
        .SelectList(list => list
            .Select(c => c.Name)
            .SelectAvg(c => c.Age))
        .List<object[]>();

see more here:

16.7. Projections

Upvotes: 1

Related Questions