skip validation when loading object

skip validation when loading object

Old forum URL: forums.lhotka.net/forums/t/991.aspx


vargasbo posted on Wednesday, August 23, 2006

I don't want my validation to execute when I load my object. Is the only way around this by using the private member, instead of the public member (setter)?


Brian Criswell replied on Wednesday, August 23, 2006

That is the general pattern, yes.  The pattern for setting a public property is to check if the value has changed, set the value and raise the PropertyChanged event.  How are you loading your object?

vargasbo replied on Wednesday, August 23, 2006

private void DataPortal_Fetch(Criteria criteria)
        {
            Database db = DatabaseFactory.CreateDatabase(DatabaseProp.CustInfoNode);
            SafeDataReader DR = new SafeDataReader(db.ExecuteReader("usp_GetCustomerMaster", criteria.CustomerID));

            if (!DR.Read())
                throw new InvalidOperationException("Unable to load CustomerMaster " + criteria.CustomerID);

            #region Load Customer
            LoadCustomerMasterFields(this, DR);

....

}

private static void LoadCustomerMasterFields(CustomerMaster customerMaster, SafeDataReader DR)
    { ///load details here}

ajj3085 replied on Wednesday, August 23, 2006

I think the body of LoadCustomerMasterFields may be helpful as well.  Smile [:)]

Copyright (c) Marimer LLC