Welcome to Microsoft .NET Framework 3.0 Community (NetFx3)

The .NET Framework is Microsoft's managed code programming model for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes.

Learn More...

WCF Community Bloggers

Tuesday, March 11, 2008 - Posts

  • CSLA .NET 3.5 code reduction with child objects

    In a previous post I talked about the new property declaration syntax options in CSLA .NET 3.5. When it comes to child objects, if the shortest form is used then CSLA will pretty much completely take care of all parent-child object interaction so you don't have to do it by hand. This is a tremendous code savings! So declaring a child property like this: private static PropertyInfo<ChildList> ChildListProperty = RegisterProperty<ChildList>(new PropertyInfo<ChildList>("ChildList"); public ChildList ChildList { get { return GetProperty<ChildList>(ChildListProperty); } } allows CSLA to manage the child object. Of course you do need to create the child object somewhere, such as in the DataPortal_XYZ methods: [RunLocal] private void DataPortal_Create() { // initialize other fields here LoadProperty<ChildList>(ChildListProperty, ChildList.NewList()); base.DataPortal_Create(); } private void DataPortal_Fetch(...) { // initialize other fields here LoadProperty<ChildList>(ChildListProperty, ChildList.GetList(this.Id)); } Another option is to use a lazy loading scheme. There are a couple options in how you can use lazy loading. You can avoid the DataPortal_Create() implementation by just creating a new, empty list - and I do this almost all the time now: private static PropertyInfo<ChildList> ChildListProperty = RegisterProperty<ChildList>(new PropertyInfo<ChildList>("ChildList"); public ChildList ChildList { get { if (!FieldManager.FieldExists(ChildListProperty)) Read More...

Copyright © 2007 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us