CodeGen Template Woes

CodeGen Template Woes

Old forum URL: forums.lhotka.net/forums/t/5846.aspx


Jack posted on Friday, November 21, 2008

I'm using a modified version of the CSLAContrib CodeSmith template to generate all my child collections and it is creating LazyLoaded lists via NewBO call however this is dying for my ReadOnlyLists which don't have the New method.

Any thoughts on how to get around this other than manually coding the read-only lists.

public FieldLookupList FieldLookups
{
 get
 {
  if (!FieldManager.FieldExists(FieldLookupsProperty))
   LoadProperty<FieldLookupList>(FieldLookupsProperty, FieldLookupList.NewFieldLookupList());
  return GetProperty<FieldLookupList>(FieldLookupsProperty);
   }
}

Any suggestions?

thanks

jack

rasupit replied on Friday, November 21, 2008

The templates does not support lazy load out of the box.  So if you need this feature, I'm afraid at the you have to modify them to suit your need.

The code snippet you described is not really intended for lazy loading.  It is more like "lazy create" which just deferred object creation until the first reference.

It's not really clear what are you trying to do here, I'm guessing that you are trying add a "convenient" read only list as property on your editable object.  Why not just create user class (a  partial class) then add this property manually.  This type of property does not need to have a backing field therefore just create as regular property as follow:

FieldLookupList _fieldLookups;
public FieldLookupList FieldLookups
{
    get {
        if (_fieldLookups == null) {
                _fieldLookups = FieldLookupList.GetFieldLookupList();
        }
         return _fieldLookups;
    }
}

HTH,
Ricky

Copyright (c) Marimer LLC