CSLA 3 to 4: Properties with private backing fields must be marked as RelationshipTypes.PrivateField

CSLA 3 to 4: Properties with private backing fields must be marked as RelationshipTypes.PrivateField

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


JJLoubser posted on Wednesday, January 19, 2011

error:

Properties with private backing fields must be marked as RelationshipTypes.PrivateField

 

 

this work in Silverlight 3 CSLA 3, but not in Siliverlight 4 CSLA 4:

 

 

public bool _loadingProvinceNVL = false;
private static PropertyInfo<ProvinceNVL> ProvinceListProperty = RegisterProperty<ProvinceNVL>(c => c.ProvinceList);
[NonSerialized]
private ProvinceNVL _provinceList = ProvinceListProperty.DefaultValue;
public ProvinceNVL ProvinceList
{
    get
    {
      if (!_loadingProvinceNVL && (!FieldManager.FieldExists(ProvinceListProperty) || ReadProperty(ProvinceListProperty) == null))
       {
#if SILVERLIGHT
          _loadingProvinceNVL = true;
          ProvinceNVL.GetProvinceNVL((o, e) =>
             {
               
               _provinceList = e.Object;
               OnPropertyChanged(ProvinceListProperty.Name);
               

               _loadingProvinceNVL = false;
              
               }
          );
#else
           _provinceList = ProvinceNVL.GetProvinceNVL();
           //LoadProperty(ProvinceListProperty, ProvinceNVL.GetProvinceNVL());
#endif
      }


      
          return GetProperty(ProvinceListProperty, _provinceList);
      
  }
}

 

how do I mark it as RelationshipTypes.PrivateField?

JJLoubser replied on Wednesday, January 19, 2011

like this:

 

public bool _loadingProvinceNVL = false;
private static PropertyInfo<ProvinceNVL> ProvinceListProperty = RegisterProperty<ProvinceNVL>(c => c.ProvinceList, "ProvinceList", RelationshipTypes.PrivateField);
[NonSerialized]
private ProvinceNVL _provinceList = ProvinceListProperty.DefaultValue;
public ProvinceNVL ProvinceList
{
    get
    {
      if (!_loadingProvinceNVL && (!FieldManager.FieldExists(ProvinceListProperty) || ReadProperty(ProvinceListProperty) == null))
       {
#if SILVERLIGHT
          _loadingProvinceNVL = true;
          ProvinceNVL.GetProvinceNVL((o, e) =>
             {
              
               _provinceList = e.Object;
               OnPropertyChanged(ProvinceListProperty.Name);
              

               _loadingProvinceNVL = false;
             
               }
          );
#else
           _provinceList = ProvinceNVL.GetProvinceNVL();
           //LoadProperty(ProvinceListProperty, ProvinceNVL.GetProvinceNVL());
#endif
      }


     
          return GetProperty(ProvinceListProperty, _provinceList);
     
  }
}

bniemyjski replied on Wednesday, January 19, 2011

Hello,

I wouldn't recommend using a private backing field with Silverlight and I would never recommend using a private backing field with collection or child business objects!

Thanks

-Blake Niemyjski

JJLoubser replied on Wednesday, January 19, 2011

why? it is working fine, we had memory problems in Silverlight 3 CSLA 3, but did not check for Silverlight 4 CSLA 4, it runs smooth so far.

JonnyBee replied on Thursday, January 20, 2011

If you need to use the NonSerialized or NotUndoable attributes then you must create a private backing field.

But that would be the only reasons (IMO) to use a private backing field.

Private backing fields as part of the BO graph will require additional code for Serialize and OnDeserialized.
Your sample code works fine as the property is a lazy loaded NVL.

ManagedProperties is the preferred and recommended property type.

Copyright (c) Marimer LLC