问题
Given the following entity-
public class Friend
{
public virtual string Name { get; set; }
public virtual IEnumerable<string> Nicknames { get; set; }
}
which is mapped like so:
mapping.HasMany(x => x.Nicknames).Element("Value") //this gets auto-mapped to a different 'Nicknames' table
given a string, I want to retrieve friend who's name or one of his nicknames matches that string.
I can't figure out how to do that.. here's what I've got so far:
.Where(Restrictions.Or(
Restrictions.On<Friend>(f => f.Name).IsInsensitiveLike(name),
Restrictions.On<Friend>(f => f.Nicknames) // i'd like to be able to do: .Contains(name)
)
).List();
回答1:
turns out that this is a known issue in nHib (and in fact, in Hibernate as well).
see here.
I ended up using the Query API for this one.
来源:https://stackoverflow.com/questions/6440055/queryover-add-restriction-on-primitive-collection