CSLA 4 DataPortal.Fetch failed (Index was outside the bounds of the array.)

CSLA 4 DataPortal.Fetch failed (Index was outside the bounds of the array.)

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


JJLoubser posted on Friday, September 10, 2010

DataPortal.Fetch failed (Index was outside the bounds of the array.) WHY?

for:

private static readonly PropertyInfo<EmployeeEC> EmployeeProperty = RegisterProperty<EmployeeEC>(p => p.Employee, RelationshipTypes.LazyLoad);
        public EmployeeEC Employee
        {
            get
            {
                if ((!FieldManager.FieldExists(EmployeeProperty) || ReadProperty(EmployeeProperty) == null))
                {
#if SILVERLIGHT
                    if (!IsBusy)
                    MarkBusy();

                    EmployeeEC.GetEmployee(CompanyGroupID,EmployeeID, (o, e) =>
             {
                 if (e.Error != null)
                     throw e.Error;
                 Employee = e.Object; // EXECUTE THE ERROR HERE AFTER SECTIONB
                 Employee.IsEditByAttendanceOfficer = true; //for viewModel navigation
                 MarkIdle();
                 OnPropertyChanged(EmployeeProperty);
                
             }
          );
#else
                    //if (!FieldManager.FieldExists(EmployeeProperty))
                    //   {
                    //     Employee = DataPortal.Fetch<EmployeeEC>().Child;
                    //     OnPropertyChanged(EmployeeProperty);
                    //   }

#endif
                }
                return GetProperty(EmployeeProperty);
            }
            set
            {
                LoadProperty(EmployeeProperty, value);
            }
        }

 

 

SECTION B: //THIS WORK

 public static void GetEmployee(int CompanyGroupID, int EmployeeID, EventHandler<DataPortalResult<EmployeeEC>> callback)
        {

            var dp = new DataPortal<EmployeeEC>();
            dp.FetchCompleted += callback;
            dp.BeginFetch(CompanyGroupID, EmployeeID); //CALL SECTIONC

        }

 

SECTION C: //THIS NEVER EXCECUTE

private void DataPortal_Fetch(int pCompanyGroupID, int pEmployeeID)
        {
        }

 

OBJECTS:

AttendanceEC

    have child  EmployeeEC

this EmployeeEC is null set at start to work for lazyload, that works fine, but when it execute the server it throws this error.

 

 

RockfordLhotka replied on Friday, September 10, 2010

DataPortal_Fetch() can only have one parameter - the criteria value.

The overload of BeginFetch() you are calling is this one:

    public void BeginFetch(object criteria, object userState)

Your second parameter is being used as userState, which is not passed through the data portal to the server. User state is maintained in memory on the client and is provided to the callback handler - it is a standard .NET technique for passing "out of band" data from the start of an async call to the handler of the async result.

Copyright (c) Marimer LLC