Junior
Junior

Reputation: 154

How use QueryOver on NHibernate to select custom result

I have this code to return all colors with have some text:

public IEnumerable<Color> FindStartingWith(string term)
{           
    return Session.QueryOver<Color>().Where(color => color.Name.IsLike(text, MatchMode.Anywhere)).List();           
}

But what I want to do, is return a STRING IEnumerable containing only a list of color.Name...

How can I do that with QueryOver?

Thanks

Junio

Upvotes: 2

Views: 1945

Answers (1)

Cole W
Cole W

Reputation: 15303

Syntax may not be exactly right but should be somethign like:

public IEnumerable<string> FindStartingWith(string term)
{           
    return Session.QueryOver<Color>()
                  .Select(color => color.Name)
                  .Where(color => color.Name.IsLike(text, MatchMode.Anywhere))
                  .List<string>();           
}

Upvotes: 7

Related Questions