Delete child objects

Delete child objects

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


Tous-Citi posted on Monday, July 18, 2011

I have just recently converted my Windows application from CSLA 3.6.2 to 4.1.0.  After many hours of converting authorization, validation and property definitions, I finally got the application to compile.  I went to run the app and found that I can no longer delete items from a child list.

From the UI I call the following (this used to work, now fails when attempting to saveitem():

 

                    AccountGroupItem parent = (AccountGroupItem)bindingSource1.Current;
                    parent.AccountGroupOmmViewableItemCollection.Remove(item);
                    saveItem(); 

Below is a copy of the Parent object and one of the Child object (sorry for all the detail). The error that I'm getting is an index out of range.  It's as though the CSLA framework is expecting x items in the list, but because of the "Remove" there's only x-1.  Did something change in how 4.1 handles child objects?  Any help will be greatly appreciated.  Thanks.

 

 

PARENT

===============================

 

using Csla;

using Csla.Data;

using System;

using System.ComponentModel.DataAnnotations;

using System.Data;

using TradeRec.DalOracle;

using Oracle.DataAccess.Client;

using Csla.Rules.CommonRules;

 

namespace TradeRec.Library.Maintenance

{

    [Serializable()]

    public partial class AccountGroupItem : BusinessBase<AccountGroupItem>

    {

 

        private static Int32 _returnCode = 0;

 

        public enum ReturnStatus

        {

            Redefined_Option_Stocks = 2,

            NO_Exercise_Assignment_Trans = 1,

            Successful = 0,

            Failed_Error = -1

        }

 

        public ReturnStatus ReturnCode

        {

            get { return (ReturnStatus)_returnCode; }

        }

 

        #region Business Properties and Methods

 

        private static PropertyInfo<decimal> AcctGroupIdProperty = RegisterProperty<decimal>(p => p.AcctGroupId);

        [System.ComponentModel.DataObjectField(true, false)]

        public decimal AcctGroupId

        {

            get { return GetProperty<decimal>(AcctGroupIdProperty); }

        }

 

        private static PropertyInfo<string> AcctGroupCdProperty = RegisterProperty<string>(p => p.AcctGroupCd);

        [Display(Name = "AcctGroupCd")]

        [Required]

        [StringLength(10)]

        public string AcctGroupCd

        {

            get { return GetProperty<string>(AcctGroupCdProperty); }

            set { SetProperty<string>(AcctGroupCdProperty, value); }

        }

 

        private static PropertyInfo<string> AcctGroupDescProperty = RegisterProperty<string>(p => p.AcctGroupDesc);

        [Display(Name = "AcctGroupDesc")]

        [StringLength(50)]

        public string AcctGroupDesc

        {

            get { return GetProperty<string>(AcctGroupDescProperty); }

            set { SetProperty<string>(AcctGroupDescProperty, value); }

        }

 

        private static PropertyInfo<decimal> GlcostCenterIdProperty = RegisterProperty<decimal>(p => p.GlcostCenterId);

        public decimal GlcostCenterId

        {

            get { return GetProperty<decimal>(GlcostCenterIdProperty); }

            set { SetProperty<decimal>(GlcostCenterIdProperty, value); }

        }

 

        private static PropertyInfo<string> GlcostCenterCdProperty = RegisterProperty<string>(p => p.GlcostCenterCd);

        [Display(Name = "GlcostCenterCd")]

        [StringLength(10)]

        public string GlcostCenterCd

        {

            get { return GetProperty<string>(GlcostCenterCdProperty); }

            set { SetProperty<string>(GlcostCenterCdProperty, value); }

        }

 

        private static PropertyInfo<string> GlcostCenterDescProperty = RegisterProperty<string>(p => p.GlcostCenterDesc);

        [Display(Name = "GlcostCenterDesc")]

        [StringLength(50)]

        public string GlcostCenterDesc

        {

            get { return GetProperty<string>(GlcostCenterDescProperty); }

            set { SetProperty<string>(GlcostCenterDescProperty, value); }

        }

 

 

        //child properties

 

        public static readonly PropertyInfo<AccountGroupOmmViewableItemList> AccountGroupOmmViewableItemCollectionProperty = RegisterProperty<AccountGroupOmmViewableItemList>(c => c.AccountGroupOmmViewableItemCollection, RelationshipTypes.Child | RelationshipTypes.LazyLoad);

        public AccountGroupOmmViewableItemList AccountGroupOmmViewableItemCollection

        {

            get

            {

                if (!FieldManager.FieldExists(AccountGroupOmmViewableItemCollectionProperty))

                {

                    if (this.IsNew)

                        LoadProperty<AccountGroupOmmViewableItemList>(AccountGroupOmmViewableItemCollectionProperty, AccountGroupOmmViewableItemList.NewAccountGroupOmmViewableItemList());

                    else

                        LoadProperty<AccountGroupOmmViewableItemList>(AccountGroupOmmViewableItemCollectionProperty, AccountGroupOmmViewableItemList.GetAccountGroupOmmViewableItemList(this));

                }

                return GetProperty<AccountGroupOmmViewableItemList>(AccountGroupOmmViewableItemCollectionProperty);

            }

            private set

            {

                LoadProperty(AccountGroupOmmViewableItemCollectionProperty, value);

                OnPropertyChanged(AccountGroupOmmViewableItemCollectionProperty);

            }

        }

 

        #endregion //Business Properties and Methods

 

        #region  Business Rules

 

        protected override void AddBusinessRules()

        {

            base.AddBusinessRules();

        }

 

        protected static void AddObjectAuthorizationRules()

        {

            // add object-level authorization rules here

            Csla.Rules.BusinessRules.AddRule(typeof(AccountGroupItem), new Csla.Rules.CommonRules.IsInRole(Csla.Rules.AuthorizationActions.CreateObject, "Administrator", "Support", "SupportISA"));

            Csla.Rules.BusinessRules.AddRule(typeof(AccountGroupItem), new Csla.Rules.CommonRules.IsInRole(Csla.Rules.AuthorizationActions.GetObject, "Administrator", "Support", "SupportISA", "ReadOnly"));

            Csla.Rules.BusinessRules.AddRule(typeof(AccountGroupItem), new Csla.Rules.CommonRules.IsInRole(Csla.Rules.AuthorizationActions.EditObject, "Administrator", "Support", "SupportISA"));

            Csla.Rules.BusinessRules.AddRule(typeof(AccountGroupItem), new Csla.Rules.CommonRules.IsInRole(Csla.Rules.AuthorizationActions.DeleteObject, "Administrator", "Support", "SupportISA"));

        }

 

        #endregion  //Business Rules

 

        #region Factory Methods

 

        public AccountGroupRiskManagerItem AddNewAccountGroupRiskManagerItem(decimal accountGroupId)

        {

            AccountGroupRiskManagerItem item = AccountGroupRiskManagerItem.NewAccountGroupRiskManagerItem(accountGroupId);

            item.RevUsrId = TradeRec.DalOracle.Database.UserId;

            item.CreateUsrId = TradeRec.DalOracle.Database.UserId;

            AccountGroupRiskManagerItemCollection.Add(item);

            return item;

        }

 

        public AccountGroupOmmViewableItem AddNewAccountGroupOmmViewableItem(decimal accountGroupId)

        {

            AccountGroupOmmViewableItem item = AccountGroupOmmViewableItem.NewAccountGroupOmmViewableItem(accountGroupId);

            item.RevUsrId = TradeRec.DalOracle.Database.UserId;

            item.CreateUsrId = TradeRec.DalOracle.Database.UserId;

            AccountGroupOmmViewableItemCollection.Add(item);

            return item;

        }

 

        public static AccountGroupItem NewAccountGroupItem()

        {

            if (!Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.GetObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to add an AccountGroupItem");

            return DataPortal.Create<AccountGroupItem>(new SingleCriteria<AccountGroupItem, decimal>(0));

        }

 

        public static AccountGroupItem NewAccountGroupItem(decimal basketId)

        {

            if (!Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.GetObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to add an AccountGroupItem");

            return DataPortal.Create<AccountGroupItem>(new SingleCriteria<AccountGroupItem, decimal>(basketId));

        }

 

        public static AccountGroupItem GetAccountGroupItem(SafeDataReader dr)

        {

            if (!Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.GetObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to view an AccountGroupItem");

            return DataPortal.Fetch<AccountGroupItem>(dr);

        }

 

        public static void DeleteAccountGroupItem(decimal basketId)

        {

            if (!Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.DeleteObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to remove an AccountGroupItem");

            DataPortal.Delete <AccountGroupItem>(new SingleCriteria<AccountGroupItem, decimal>(basketId));

        }

 

        public override AccountGroupItem Save()

        {

            if (IsDeleted && !Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.DeleteObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to remove an AccountGroupItem");

            else if (IsNew && !Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.CreateObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to add an AccountGroupItem");

            else if (!Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.EditObject, typeof(AccountGroupItem)))

                throw new System.Security.SecurityException("User is not authorized to edit an AccountGroupItem");

 

            return base.Save();

        }

 

        private AccountGroupItem()

        { /* require use of factory method */ }

 

        #endregion //Factory Methods

 

        #region Data Access

 

        #region Data Access - Create

        [RunLocal]

        private void DataPortal_Create(SingleCriteria<AccountGroupItem, decimal> criteria)

        {

            bool cancel = false;

            OnCreating(criteria, ref cancel);

            if (cancel) return;

 

            LoadProperty<decimal>(AcctGroupIdProperty, criteria.Value);

 

            OnCreated();

        }

 

        partial void OnCreating(SingleCriteria<AccountGroupItem, decimal> criteria, ref bool cancel);

        partial void OnCreated();

        #endregion //Data Access - Create

 

        #region Data Access - Fetch

        private void FetchObject(SafeDataReader dr)

        {

 

            //Debug.WriteLine(dr.GetString("BASKET_DESC"));

 

            LoadProperty<decimal>(AcctGroupIdProperty, dr.GetDecimal("ACCT_GROUP_ID"));

            LoadProperty<string>(AcctGroupCdProperty, dr.GetString("ACCT_GROUP_CD"));

            LoadProperty<string>(AcctGroupDescProperty, dr.GetString("ACCT_GROUP_DESC"));

 

            OnMemberLoaded();

        }

 

        private void DataPortal_Fetch(SafeDataReader dr)

        {

            bool cancel = false;

            OnFetching(dr, ref cancel);

            if (cancel) return;

 

            OnMemberLoading();

            FetchObject(dr);

 

            // BDT - Do not validate when fetching data.  Some rules can only be applied on update.

            //BusinessRules.CheckRules();

            OnFetched();

        }

 

        partial void OnFetching(SafeDataReader dr, ref bool cancel);

        partial void OnFetching(SingleCriteria<AccountGroupItem, decimal> criteria, ref bool cancel);

        partial void OnFetched();

        partial void OnMemberLoading();

        partial void OnMemberLoaded();

        #endregion //Data Access - Fetch

 

        #region  Data Access - Insert/Update

 

        private void AddDbParameters(ref OracleCommand cmd, bool isInsert)

        {

            OracleParameter parmAcctGroupId = new OracleParameter("acct_group_id_IN", OracleDbType.Int32, ParameterDirection.Input);

            parmAcctGroupId.Value = AcctGroupId;

            if (!isInsert) cmd.Parameters.Add(parmAcctGroupId);

 

            OracleParameter parmAcctGrpCd = new OracleParameter("acct_group_cd_IN", OracleDbType.Varchar2, ParameterDirection.Input);

            parmAcctGrpCd.Value = AcctGroupCd;

            cmd.Parameters.Add(parmAcctGrpCd);

 

            OracleParameter parmAcctGrpDesc = new OracleParameter("acct_group_desc_IN", OracleDbType.Varchar2, ParameterDirection.Input);

            parmAcctGrpDesc.Value = AcctGroupDesc;

            cmd.Parameters.Add(parmAcctGrpDesc);

 

            OracleParameter parmGlCostCenterId = new OracleParameter("glcost_center_id_IN", OracleDbType.Int32, ParameterDirection.Input);

            parmGlCostCenterId.Value = GlcostCenterId;

            if (!isInsert) cmd.Parameters.Add(parmGlCostCenterId);

 

            OracleParameter parmAcctGroupIdOut = new OracleParameter("acct_group_id_OUT", OracleDbType.Int32, ParameterDirection.Output);

            if (isInsert) cmd.Parameters.Add(parmAcctGroupIdOut);

 

            OracleParameter parmRC = new OracleParameter("rc_out", OracleDbType.Int32, ParameterDirection.Output);

            cmd.Parameters.Add(parmRC);

        }

        #endregion  //Data Access - Insert/Update

 

        #region Data Access - Insert

        private void ExecuteInsert(ConnectionManager<OracleConnection> ctx)

        {

            OracleCommand cmd = new OracleCommand();

            cmd.Connection = ctx.Connection;

            cmd.CommandText = "sp_maintain.acct_group_insert";

            cmd.CommandType = CommandType.StoredProcedure;

            AddDbParameters(ref cmd, true);

 

            cmd.ExecuteNonQuery();

 

            LoadProperty<decimal>(AcctGroupIdProperty, Convert.ToDecimal(((OracleParameter)cmd.Parameters[cmd.Parameters.IndexOf("acct_group_id_OUT")]).Value.ToString()));

        }

 

 

        protected override void DataPortal_Insert()

        {

            bool cancel = false;

            OnInserting(ref cancel);

            if (cancel) return;

 

            OracleTransaction tn;

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

            {

                tn = ctx.Connection.BeginTransaction();

                OnMemberReading();

                ExecuteInsert(ctx);

                OnMemberRead();

 

                tn.Commit();

 

                //Insert Child object(s)

                FieldManager.UpdateChildren(this);

            }

            OnInserted();

        }

 

        partial void OnInserting(ref bool cancel);

        partial void OnInserted();

        partial void OnMemberReading();

        partial void OnMemberRead();

        #endregion //Data Access - Insert

 

        #region Data Access - Update

        private void ExecuteUpdate(ConnectionManager<OracleConnection> ctx)

        {

            OracleCommand cmd = new OracleCommand();

            cmd.Connection = ctx.Connection;

            cmd.CommandText = "sp_maintain.acct_group_update";

            cmd.CommandType = CommandType.StoredProcedure;

            AddDbParameters(ref cmd, false);

 

            cmd.ExecuteNonQuery();

        }

 

        protected override void DataPortal_Update()

        {

            bool cancel = false;

            OnUpdating(ref cancel);

            if (cancel) return;

            OracleTransaction tn;

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

            {

                tn = ctx.Connection.BeginTransaction();

 

                OnMemberReading();

                if (IsSelfDirty)

                {

                    ExecuteUpdate(ctx);

                }

 

                //Update Child object(s)

                //DataPortal.UpdateChild(ReadProperty<BasketStockItemList>(BasketStockCollectionProperty), this);

                FieldManager.UpdateChildren(this);

                OnMemberRead();

 

                tn.Commit();

            }

            OnUpdated();

        }

        partial void OnUpdating(ref bool cancel);

        partial void OnUpdated();

        #endregion //Data Access - Update

 

 

        #region Data Access - Delete

        protected override void DataPortal_DeleteSelf()

        {

            bool cancel = false;

            OnSelfDeleting(ref cancel);

            if (cancel) return;

 

            OracleTransaction tn;

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

            {

                OnMemberSelfDeleting();

 

                OracleCommand cmd = new OracleCommand();

                cmd.Connection = ctx.Connection;

                cmd.CommandText = "sp_maintain.acct_group_delete";

                cmd.CommandType = CommandType.StoredProcedure;

 

                OracleParameter parmId = new OracleParameter("acct_group_id_IN", OracleDbType.Int32, ParameterDirection.Input);

                parmId.Value = ReadProperty<decimal>(AcctGroupIdProperty);

                cmd.Parameters.Add(parmId);

 

                OracleParameter parmRC = new OracleParameter("rc_out", OracleDbType.Int32, ParameterDirection.Output);

                cmd.Parameters.Add(parmRC);

 

                tn = cmd.Connection.BeginTransaction();

 

                //Delete Child object(s), which may contain concurrency check

                FieldManager.UpdateChildren(this);

 

                cmd.ExecuteNonQuery();

                tn.Commit();

 

                _returnCode = Convert.ToInt32(parmRC.Value.ToString());

 

            }

            SetProperty<AccountGroupOmmViewableItemList>(AccountGroupOmmViewableItemCollectionProperty, AccountGroupOmmViewableItemList.GetAccountGroupOmmViewableItemList(this));

 

            OnSelfDeleted();

        }

 

        partial void OnSelfDeleting(ref bool cancel);

        partial void OnSelfDeleted();

        partial void OnMemberSelfDeleting();

        partial void OnMemberSelfDeleted();

 

        private void DataPortal_Delete(SingleCriteria<AccountGroupItem, decimal> criteria)

        {

            bool cancel = false;

            OnDeleting(criteria, ref cancel);

            if (cancel) return;

 

            OracleTransaction tn;

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

            {

                OnMemberDeleting();

                ////Delete Child object(s)

                //mgr.DataContext.BasketStockItem.DeleteAllOnSubmit(data.BasketStockItem);

 

                OracleCommand cmd = new OracleCommand();

                cmd.Connection = ctx.Connection;

                cmd.CommandText = "sp_maintain.acct_group_delete";

                cmd.CommandType = CommandType.StoredProcedure;

 

                OracleParameter parmId = new OracleParameter("acct_group_id_IN", OracleDbType.Int32, ParameterDirection.Input);

                parmId.Value = criteria.Value;

                cmd.Parameters.Add(parmId);

 

                OracleParameter parmRC = new OracleParameter("rc_out", OracleDbType.Int32, ParameterDirection.Output);

                cmd.Parameters.Add(parmRC);

 

                tn = cmd.Connection.BeginTransaction();

                cmd.ExecuteNonQuery();

                tn.Commit();

                OnMemberDeleted();

 

                if (System.Convert.ToInt32(parmRC.Value.ToString()) == 0)

                    throw new Exception("Unable to delete the account group record.");

            }

 

            SetProperty<AccountGroupOmmViewableItemList>(AccountGroupOmmViewableItemCollectionProperty, AccountGroupOmmViewableItemList.GetAccountGroupOmmViewableItemList(this));

 

            OnDeleted();

        }

 

        partial void OnDeleting(SingleCriteria<AccountGroupItem, decimal> criteria, ref bool cancel);

        partial void OnDeleted();

        partial void OnMemberDeleting();

        partial void OnMemberDeleted();

        #endregion //Data Access - Delete

        #endregion //Data Access

    }

}

 

 

 

CHILD

==========================

using Csla;

using Csla.Data;

using Csla.Security;

using System;

using System.ComponentModel.DataAnnotations;

using System.Data;

using System.Transactions;

using TradeRec.DalOracle;

using Oracle.DataAccess.Client;

using Oracle.DataAccess.Types;

using Csla.Rules.CommonRules;

 

namespace TradeRec.Library.Maintenance

{

    [Serializable()]

    public partial class AccountGroupOmmViewableItem : BusinessBase<AccountGroupOmmViewableItem>

    {

        #region Business Properties and Methods

 

        private static PropertyInfo<decimal> AccountGroupIdProperty = RegisterProperty<decimal>(p => p.AccountGroupId, RelationshipTypes.Child);

        [System.ComponentModel.DataObjectField(true, false)]

        public decimal AccountGroupId

        {

            get { return GetProperty<decimal>(AccountGroupIdProperty); }

            set { SetProperty<decimal>(AccountGroupIdProperty, value); }

        }

 

        private static PropertyInfo<string> AgViewCdProperty = RegisterProperty<string>(p => p.AgViewCd, RelationshipTypes.Child);

        public string AgViewCd

        {

            get { return GetProperty<string>(AgViewCdProperty); }

            set { SetProperty<string>(AgViewCdProperty, value); }

        }

 

        private static PropertyInfo<decimal> AgViewIdProperty = RegisterProperty<decimal>(p => p.AgViewId, RelationshipTypes.Child);

        [System.ComponentModel.DataObjectField(true, false)]

        public decimal AgViewId

        {

            get { return GetProperty<decimal>(AgViewIdProperty); }

            set { SetProperty<decimal>(AgViewIdProperty, value); }

        }

 

        #endregion //Business Properties and Methods

 

        #region Validation Rules

        protected override void AddBusinessRules()

        {

            base.AddBusinessRules();

        }

        #endregion //Validation Rules

 

        #region Factory Methods

 

        internal static AccountGroupOmmViewableItem NewAccountGroupOmmViewableItem(decimal accountGroupId)

        {

            return DataPortal.CreateChild<AccountGroupOmmViewableItem>(accountGroupId);

        }

 

        internal static AccountGroupOmmViewableItem GetAccountGroupOmmViewableItem(SafeDataReader dr)

        {

            return DataPortal.FetchChild<AccountGroupOmmViewableItem>(dr);

        }

 

        private AccountGroupOmmViewableItem()

        { /*  require use of factory method */ }

        #endregion //Factory Methods

 

        #region Data Access

 

        #region SQLText

        [Serializable()]

        private class SQL

        {

            public string Select;

            public string Insert;

            public string Delete;

 

            public SQL(decimal accountGroupId)

            {

                System.Text.StringBuilder sb = new System.Text.StringBuilder();

 

                sb.Append("SELECT a.acct_group_id, a.ag_view_id, b.acct_group_cd as ag_view_cd, a.create_dt, ");

                sb.Append("   a.create_usr_id, a.rev_dt, a.rev_usr_id ");

                sb.Append("FROM   ag_viewable a, acct_group b ");

                sb.Append("WHERE a.ag_view_id = b.acct_group_id ");

                sb.Append("  AND a.acct_group_id = " + accountGroupId.ToString() + " ");

                sb.Append("ORDER BY INITCAP (b.trading_staff_nm) ASC ");

                this.Select = sb.ToString();

            }

 

            public SQL(bool isDelete, decimal accountGroupId, decimal agViewId)

            {

                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                if (isDelete)

                {

                    sb.Append("DELETE FROM ag_viewable a ");

                    sb.Append("WHERE  a.acct_group_id = " + accountGroupId.ToString() + " ");

                    sb.Append("  AND a.ag_view_id = " + agViewId.ToString());

                    this.Delete = sb.ToString();

                }

                else

                {

                    sb.Append("INSERT INTO ag_viewable  ");

                    sb.Append("(ag_view_id, acct_group_id, create_dt, create_usr_id, rev_dt, rev_usr_id ) VALUES (");

                    sb.Append(agViewId.ToString() + "," + accountGroupId.ToString() + ",SYSDATE,USER,SYSDATE,USER) ");

                    this.Insert = sb.ToString();

                }

            }

        }

        #endregion //SQLText

 

        #region Criteria

 

        [Serializable()]

        private class Criteria

        {

            public decimal AccountGroupId;

 

            public Criteria(decimal accountGroupId)

            {

                this.AccountGroupId = accountGroupId;

            }

        }

 

        #endregion //Criteria

 

 

        #region Data Access - Create

        private void Child_Create(decimal accountGroupId)

        {

            bool cancel = false;

            OnCreating(accountGroupId, ref cancel);

            if (cancel) return;

 

            LoadProperty<decimal>(AccountGroupIdProperty, accountGroupId);

            BusinessRules.CheckRules();

 

            OnCreated();

        }

 

        partial void OnCreating(decimal accountGroupId, ref bool cancel);

        partial void OnCreated();

        #endregion //Data Access - Create

 

        #region Data Access - Fetch

        private void FetchObject(SafeDataReader dr)

        {

            LoadProperty<decimal>(AccountGroupIdProperty, dr.GetDecimal("ACCT_GROUP_ID"));

            LoadProperty<string>(AgViewCdProperty, dr.GetString("AG_VIEW_CD"));

            LoadProperty<decimal>(AgViewIdProperty, dr.GetDecimal("AG_VIEW_ID"));

        }

 

        private void Child_Fetch(Criteria criteria)

        {

            MarkAsChild();  // Because of Lazy Loading, we need to mark this object as a child object.

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

            {

                OracleCommand cmd = new OracleCommand();

                cmd.Connection = ctx.Connection;

                cmd.CommandText = new SQL(criteria.AccountGroupId).Select;

                cmd.CommandType = CommandType.Text;

 

                SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader());

 

                bool cancel = false;

                OnLoading(dr, ref cancel);

                if (cancel) return;

 

                dr.Read();

                FetchObject(dr);

            }

 

            BusinessRules.CheckRules();

 

            OnLoaded();

        }

 

        private void Child_Fetch(SafeDataReader dr)

        {

            bool cancel = false;

            OnLoading(dr, ref cancel);

            if (cancel) return;

 

            FetchObject(dr);

            BusinessRules.CheckRules();

 

            OnLoaded();

        }

 

        partial void OnLoading(SafeDataReader dr, ref bool cancel);

        partial void OnLoaded();

        #endregion //Data Access - Fetch

 

        #region Data Access - Insert

        private void ExecuteInsert(ConnectionManager<OracleConnection> ctx, AccountGroupItem parent)

        {

            OracleCommand cmd = new OracleCommand();

            cmd.Connection = ctx.Connection;

            cmd.CommandText = new SQL(false, parent.AcctGroupId, AgViewId).Insert;

            cmd.CommandType = CommandType.Text;

            cmd.ExecuteNonQuery();

        }

 

        private void Child_Insert(AccountGroupItem parent)

        {

            bool cancel = false;

            OnInserting(parent, ref cancel);

            if (cancel) return;

 

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

                ExecuteInsert(ctx, parent);

 

            OnInserted();

        }

 

        partial void OnInserting(AccountGroupItem parent, ref bool cancel);

        partial void OnInserted();

        partial void OnMemberReading();

        partial void OnMemberRead();

        #endregion //Data Access - Insert

 

        #region Data Access - DeleteSelf

        private void ExecuteDelete(ConnectionManager<OracleConnection> ctx)

        {

            OracleCommand cmd = new OracleCommand();

            cmd.Connection = ctx.Connection;

            cmd.CommandText = new SQL(true, AccountGroupId, AgViewId).Delete;

            cmd.CommandType = CommandType.Text;

            cmd.ExecuteNonQuery();

        }

 

        private void Child_DeleteSelf(ExchangeItem parent)

        {

            bool cancel = false;

            OnSelfDeleting(parent, ref cancel);

            if (cancel) return;

            OnMemberSelfDeleting();

            using (var ctx = TradeRec.DalOracle.ConnectionManager.GetManager(Database.ConnectionString))

            {

                ExecuteDelete(ctx);

            }

 

            OnMemberSelfDeleted();

            OnSelfDeleted();

        }

        partial void OnSelfDeleting(ExchangeItem parent, ref bool cancel);

        partial void OnSelfDeleted();

        partial void OnMemberSelfDeleting();

        partial void OnMemberSelfDeleted();

        #endregion //Data Access - DeleteSelf

 

 

        #endregion //Data Access

    }

}

 

 

 

 

 

JonnyBee replied on Monday, July 18, 2011

I think you have a wrong parameter type in Child_DeleteSelf:

Is:

private void Child_DeleteSelf(ExchangeItem parent)

Should be:

private void Child_DeleteSelf(AccountGroupItem parent).

When you use FieldManager.UpdateCildren(parent) you must make sure to have the SAME parameter types for ALL Child_XYZ methods as the argument you send into UpdateChilder or UpdateChild.

So what happends is that FieldManager can not find an appropriate Child_DeleteSelf method that accepts an AccountGroupItem.

Tous-Citi replied on Tuesday, July 19, 2011

Thank-you sooo much!Big Smile  This is some of the remnant code that was left over from the CSLA 2.0 implementation.  This conversion to 4.0 has been a good clean-up project.  On with the new.  Thanks again.

Copyright (c) Marimer LLC