/// <summary> /// Performs initialization tasks on the Business Object. /// </summary> /// <remarks> /// Initializes CSLA specific fields based on the data that was read /// into the fields marked up for NHibernate. /// </remarks> protected override void Init() { // Initialize the CSLA SmartDate fields from the NHibernate ones // Original CSLA code did this in the DataPortal_Fetch: // _started = dr.GetSmartDate("Started", _started.EmptyIsMin); // _ended = dr.GetSmartDate("Ended", _ended.EmptyIsMin); _started = Convert.ToSmartDate(_startedOn, _started.EmptyIsMin); _ended = Convert.ToSmartDate(_endedOn, _ended.EmptyIsMin); // The Project object is now loaded, so populate the child ProjectResources list. // NOTE: // The ProjectResources BOs are actually already in memory at this point because // of the way we have mapped the relationship with NHibernate. So all we need to do // is move the BOs from the NHibernate ISet to the CSLA List. _resources.Add(_projectResourcesSet); }
/// <summary> /// Insert or update a Business Object using an NHibernate <see cref="ISession"/>. /// </summary> /// <param name="session">An object that implements the <see cref="ISession"/> interface.</param> /// <remarks>You may wish to override this to perform additional processing before OR after /// a Business Object is deleted from the database. This is usually applicable in parent-child relationships. /// If overridden, ensure that you call the base method before or after your code.</remarks> public override void Save(ISession session) { // Convert the CSLA SmartDate to the correct database type _startedOn = Convert.ToNullableDateTime(_started); _endedOn = Convert.ToNullableDateTime(_ended); base.Save(session); // Check that all resources have valid links to this BO... foreach (ProjectResource projectResource in _resources) { // If new, then set the link to this BO correctly if (projectResource.IsNew) { projectResource.ProjectId = _id; } } // Get the list to persist itself _resources.Save(session); }