有没有办法用NHibernate创建惰性自定义属性?
我有一个自定义属性(在网格中绑定),如下所示:有没有办法用NHibernate创建惰性自定义属性?,nhibernate,lazy-loading,Nhibernate,Lazy Loading,我有一个自定义属性(在网格中绑定),如下所示: public class MyClass { public virtual IList<clsClass2> MyList{ get; set; } //Lazy loaded public virtual string CustomProperty //To use on Grid Binding { get { if (!
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;
}
}
}
公共类MyClass
{
公共虚拟IList MyList{get;set;}//延迟加载
要在网格绑定中使用的公共虚拟字符串CustomProperty//
{
得到
{
如果(!MyList.IsNullOrEmpty())
返回MyList.Select(\uuuu comp=>\uuuu comp.Name).ToList().ToString(,);
返回字符串。空;
}
}
}
它的工作很好。。。但这样一来,每次我加载MyClass对象时,它都会加载每个MyList元素,因为CustomProperty
有更好的方法吗
谢谢
并使用聚合字符串的数据库语法交换
…
,其中公式组尝试使用XML路径,但出现错误。。。我发现:。。。所以我认为我不能在NHibernate公式上使用XML路径。。。。还有别的办法吗?
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)");