2

I have a very basic model:

public class Blog : UniqueEntity<Guid>
{
    public virtual string Name { get; set; }
    public virtual string Tagline { get; set; }
    public virtual string ActiveThemeName { get; set; }
    public virtual string MainDomain { get; set; }
    public virtual IList<string> DomainAliases { get; set; } = new List<string>();
}

I need to write an NHibernate QueryOver query WHERE "hostname string" IN DomainAliases.

I've found a lot of answers here on SO on how I would do this in the reverse direction, ie: `WHERE DomainAliases CONTAINS "hostname string" but none for what I need.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
John Carruthers
  • 123
  • 1
  • 7

1 Answers1

2

The solution, as described here:

NHibernate: Select item with entry in element bag

should be like this:

var demos = this.session.CreateCriteria<Blog>()
    .CreateAlias("DomainAliases", "d")

    // .elemnts is what we need
    .Add(Restrictions.Eq("d.elements", "hostname string"))

    .List<Blog>();

Also check the:

NHibernate How do I query against an IList property?

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • It's not a QueryOver query but it does work. I try and stay away from the criteria API though, too many magic strings and chances for typos for my liking. – John Carruthers Dec 18 '15 at 18:21