Hi.
My CompanyCollection (BusinessListBase) class contains Company children which derives from LiteCompany (BusinessBase). My Company child class has a member/property of type WebsiteCollection (BusinessListBase). The WebsiteCollection member/property looks like this in my Company class:
private
WebsiteCollection mobjWebsiteCollection = null;[
MyDataMemberAttribute(true)]The DataPortal_Fetch method in Company contains the following, which populates the WebsiteCollection:
WebsiteCollection
objWebsiteCollection = WebsiteCollection.GetWebsiteCollection(criteria.CompanyID, criteria.WebsiteID);Please can somebody tell me where I'm going wrong?
Thanks.
Normally the property for a child object is read-only. You don't want the UI developer to accidentally alter your child out from under you! CSLA doesn't support that by itself - you'd have to make very sure to handle that event properly!!!
If the property is read-only as recommended, then your data portal code won't compile - which is good - you shouldn't be setting the property. Instead, you should be setting the backing field for the property. Look at Chapters 7/8 and ProjectTracker.Library for numerous examples.
Using something like this:
return (mobjWebsiteCollection == null) ? WebsiteCollection.NewWebsiteCollection() : mobjWebsiteCollection;
presents a problem, since you create a new collection but never assign it to "mobjWebsiteCollection". Thus, every time you try to "get" your collection, you're potentially getting a new one. I'm guessing that's why your original code doesn't work.
On another note, you're using an old property construct that you shouldn't be using anymore. The "NoInlining" method of property coding has proven to be too quirky and unstable for general use, so Rocky has deprecated its use in newer versions of the framework. The recommended practice is to not use the "NoInlining" attribute and use the method overloads of "CanReadProperty" and "PropertyHasChanged" that take a property name.
However, I'm wondering why you have a "set" for this property anyway. It's pretty unusual to have one for collection properties. If you have it because of your issue, then I'd suggest you get rid of it once we get your "get" routine cleaned up. If you do need to keep it, then you should add a call to "CanWriteProperty" in there as well, so that your security is maintained. Again, that call should have your property name in it.
So - assuming you don't need the "set", your property should look something like this:
[MyDataMemberAttribute(true)]
public WebsiteCollection WebsiteCollection
{
get
{
CanReadProperty("WebsiteCollection", true);
if (mobjWebsiteCollection == null)
mobjWebsiteCollection = WebsiteCollection.NewWebsiteCollection();
return mobjWebsiteCollection;
}
}
And if you do need the "set", it should look something like this:
set
{
CanWriteProperty("WebsiteCollection", true);
if (mobjWebsiteCollection != value)
{
mobjWebsiteCollection = value;
PropertyHasChanged("WebsiteCollection");
}
}
All your BO properties should be constructed similarly.
HTH
- Scott
tmg4340:Using something like this:
return (mobjWebsiteCollection == null) ? WebsiteCollection.NewWebsiteCollection() : mobjWebsiteCollection;
presents a problem, since you create a new collection but never assign it to "mobjWebsiteCollection".
LOL. What an idiot I am! :)
Cheers, Scott.
Copyright (c) Marimer LLC