nHibernate Criteria for selecting a parent if a child in a collection has a specific value -


if have following class structure nhibernate criteria select parent if 1 of it's children has specific name?

 public class child  {      public int id { get; set; }      public int name { get; set; }  }   public class parent  {      public int id { get; set; }      public ilist<child> children { get; set; }  } 

i'd create alias collection , add restrictions.

var parentswithkidname = session.createcriteria<parent>()     .createalias("children", "c", jointype.innerjoin)     .add(restrictions.eq("c.name", childname))     .setresulttransformer(transformers.distinctrootentity())      .list<parent>(); 

this result in

select p.*  parent p  inner join child c on /* it's mapped? */ c.name = ? 

the distinct root entity transformer process result set , remove duplicated parents. still come across wire though.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -