CSLA 3.5 - ChildrenCollection is nullCSLA 3.5 - ChildrenCollection is null
Old forum URL: forums.lhotka.net/forums/t/4583.aspx
moglir posted on Saturday, March 29, 2008
I built an example based on the ProjectTrackercs Library:
Project project = Project.NewProject();
project.Name = "testProj";
project.Started = DateTime.Now.ToString();
project = project.Save();
Resource resource = Resource.NewResource();
resource.FirstName = "Foo";
resource.LastName = "Bar";
resource = resource.Save();
ProjectResources pr = project.Resources;
pr.Assign(resource.Id);
The problem is that pr is null, so pr.Assign(resource.Id) throws an error.
What am I doing wrong?
Thank you!
Elizabeth replied on Saturday, March 29, 2008
Looks like your missing project.Resources = resources;
moglir replied on Saturday, March 29, 2008
project.Resources is a read-only field (I didn't define it like this - it is Rocky Lhotkas code in ProjectTracker.Library).
As far as I undestand, project.Resources should be an empty collection where I can add Items. The problem is, that it is null.
JoeFallon1 replied on Monday, March 31, 2008
Since it is null you are responsible for initializing it.
When you call Project project = Project.NewProject();
the code for new project should initialize it.
Joe
Copyright (c) Marimer LLC