Anticipated effort to move from CSLA .NET 1.x to 2.0

Home | Blog | Bio and Contact | CSLA .NET | CSLA Store

02 November 2005

Quite a few people have asked me about the effort that will be required to move an application from CSLA .NET 1.0 to CSLA .NET 2.0. The list of changes in the

change log can look daunting after all…

<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /> 

Fortunately most of the changes in the change log are internal – they don’t directly impact your code in a business class all that much, at least for code written using more recent versions of the framework (1.3 or higher).   In fact, the closer your code is to version 1.51 (the current version) the easier the port will be. The closer to the original 1.0 version in the books the harder.   The three big change areas are generics, BrokenRules and the DataPortal.   Generics mean there are new and different base classes from which you inherit. In most cases changing to the new base class means removing some now unneeded code from your business class. The following table lists the base classes:  
Old New
BusinessBase BusinessBase(Of T)


T = your business object type
BusinessCollectionBase BusinessListBase(Of T, C)

BusinessListBase<T, C>

T = your collection type

C = child object type
NameValueCollectionBase NameValueListBase(Of K, V)

NameValueListBase<K, V>

K = type of the key or name

V = type of the value
ReadOnlyBase ReadOnlyBase(Of T)


T = your business object type
ReadOnlyCollectionBase ReadOnlyListBase(Of T)


T = child object type
  The only place where you need to add code is BusinessBase(Of T), where there’s a new GetIdValue method you must implement (typically with one line of code). In all cases you will remove code such as the System.Objects overrides region and tons of code in collections.   A much bigger changes is that BrokenRules has been replaced by ValidationRules and now only supports the idea of rule methods. The BrokenRules.Assert() concept is gone. This will be the biggest change for most people, as all Assert calls must be converted to rule methods. Fortunately that's not terribly hard, but it is work.   DataPortal used to call DataPortal_Update, forcing you to write a nested If..Then statement inside DataPortal_Update. It now calls DataPortal_Insert, DataPortal_Update or DataPortal_DeleteSelf as appropriate. So now you write 3 methods instead of 1, but each method is very focused and requires no conditionals. Also, DataPortal now calls MarkNew and MarkOld automatically so you don't need to make those calls (or forget to make them like I typically did...).   The end result is that all properties in a BusinessBase(Of T) business object will now look like this:   private string _name = string.Empty;   public string Name {   get   {     if (CanReadProperty())       return _name;     else       throw new System.Security.SecurityException(         "Property get not allowed");   }   set   {     if (CanWriteProperty())       if (_name != value)       {         _name = value;         PropertyHasChanged();       }     else       throw new System.Security.SecurityException(         "Property set not allowed");   } }   Or   Private mName As String = ""   Public Property Name() As String   Get     If CanReadProperty() Then       Return mName     Else       Throw New System.Security.SecurityException( _         "Property get not allowed")     End If   End Get   Set(ByVal value As String)     If CanWriteProperty() Then       If mName <> value Then         mName = value         PropertyHasChanged()       End If     Else       Throw New System.Security.SecurityException( _         "Property set not allowed")     End If   End Set End Property     The new Expert VB/C# 2005 Business Objects books and thus the CSLA .NET 2.0 framework are slated for public release in Mar/Apr 2006.