0

I have a custom property (to binding in a Grid) like that :

public class MyClass
{ 
       public virtual IList<clsClass2> MyList{ get; set; }  //Lazy loaded
       public virtual string CustomProperty //To use on Grid Binding
       {
          get
          {
             if (!MyList.IsNullOrEmpty())
                return MyList.Select(__comp => __comp.Name).ToList().ToString(", ");
                return string.Empty;
          }
       }   
}

Its working fine... But that way everytime I load a MyClass object, its load every MyList element because of the CustomProperty...

Is there a better way to do that?

Thanks

Paul
  • 12,359
  • 20
  • 64
  • 101

1 Answers1

1
 public virtual string CustomProperty //To use on Grid Binding
 {
    get; private set;
 }

// using FLuentMapping
Map(x => x.CustomProperty).Formula("(SELECT ... FROM Class2Table c2 WHERE c2.MyClass_id = Id)");

and exchange ... with your database syntax of aggregating the string see here

Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94
  • Tried using XML PATH, but got an error... I found that : https://nhibernate.jira.com/browse/NH-2132 ... So I think I cannot use XML PATH on NHibernate Formula.... Is there any other way? – Paul Mar 12 '12 at 13:38