开发者

How to manually create Proxy for Detail Collection in NHibernate

I've got class, let it be Foo:

public class Foo
{ 
  ...

  protected MyCollection<Detail> _details
  public virtual MyCollection<Detail> Details 
  {
     get { return _details ?? new MyCollection<Details开发者_Python百科>(); }
     set { _details = value; ... } 
  }
  ...
}

public class Detail {...}

When I do LINQ query:

var q = session.Query<Foo>().Select(foo => new Foo( property1 = foo.property1, ... );
...
q.ToList();

I've got NULL in _details field, and when I access to Details to get all Lazy details, of course I get new MyCollection(), but not IPersistentBag (or else, IPersistentCollection).

So How can I manually create proxy collection (I've got session / sessionFactory references)?

[ Added ] here is the mappings (on Foo):

<bag name="Details" lazy="true" collection-type="NHibernateDataService.DetailBag`1[[DataObjects.Detail, DataObjects]], NHibernateDataService" cascade="all-delete-orphan" fetch="select" batch-size="1" access="property" inverse="true">
  <key column="`Master`" />
  <one-to-many class="DataObjects.Detail" />
</bag>

Thank you!


MyCollection can't be mapped to IPersistentBag, unless, of course, you implement that interface on MyCollection (and probably set the mapping type explicitly??)...

A more standard approach is to set the "collection-type" property on the bag mapping to a custom type - an implementation of IUserCollectionType, which you can choose to make a base class that MyCollection derives from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜