NHibernate: Select item with entry in element bag

前端 未结 2 633
醉梦人生
醉梦人生 2020-12-12 02:04

I have a class with property of list.

public class Paperboy{
     private int _id;
     private string _lastname;
     private string _firstname;
     privat         


        
相关标签:
2条回答
  • 2020-12-12 02:35

    Seems like NHibernate < 4 has a bug with creating the join. With the help of Radim Köhler and firo (see other Post) I ended up using HQL:

    select
       paperboy
    from
       Paperboy as paperboy 
    left join 
       paperboy._additionalPhoneNumbers number
    where
       paperboy._mobile = :nr or
       paperboy._phone = :nr or
       number = :nr
    

    It is also possible to avoid the join by using :nr in elements(paperboy._additionalPhoneNumbers) but than I could not replace some characters in the additional number.

    0 讨论(0)
  • 2020-12-12 02:51

    Almost the same answer I just gave to previous NHibernate question: QueryOver IList<string> property

    Based on this Q & A: NHibernate How do I query against an IList property?

    Where I tried to show that (as mentioned in the documentation) we can use magical word ".elements":

    17.1.4.1. Alias and property references

    So the query which will touch the string elements in your case

    //or.Add(Restrictions.Eq("AdditionalPhoneNumbers", number));
    or.Add(Restrictions.Eq("AdditionalPhoneNumbers.elements", number));
    

    And that will support filtering IList<string>

    0 讨论(0)
提交回复
热议问题