QueryOver - add restriction on primitive collection

可紊 提交于 2019-12-08 03:26:02

问题


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

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