4.x Lazy Load exception : DataPortal.Fetch failed on the server

4.x Lazy Load exception : DataPortal.Fetch failed on the server

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


hramos360 posted on Wednesday, July 13, 2011

I'm trying to lazy load a child collection(BusinessListBase) from a parent (BusinessBase) by fetching the results from a child list creator class as discussed in the e-books.  Any ideas why I'm getting a ""DataPortal.Fetch failed on server" exception?

 private static readonly PropertyInfo<Phones> PhonesProperty = RegisterProperty<Phones>(c => c.Phones, RelationshipTypes.Child | RelationshipTypes.LazyLoad);
public Phones Phones
{
    get
    {
        if(!FieldManager.FieldExists(PhonesProperty))
       
{
         
var creator = DataPortal.Fetch<PhoneListCreator>();
          Phones = creator.Result;
        
}
        return ReadProperty(PhonesProperty);
    }
   
private set
   
{
      LoadProperty(PhonesProperty,
value);
    
}
}

 

 [Serializable]
public partial class PhoneListCreator : ReadOnlyBase<PhoneListCreator>
{
    public static PropertyInfo<Phones> ResultProperty =RegisterProperty<Phones>c => c.Result);
    public Phones Result
    {
       get { return GetProperty(ResultProperty); }
      
private set { LoadProperty(ResultProperty, value); }
    }

    public static PhoneListCreator GetPhoneListCreator(int id)
    {
       
return DataPortal.Fetch<PhoneListCreator>(id);
    }

 

 

    private void DataPortal_Fetch(int id)
    {
       Result =
DataPortal.CreateChild<Phones>(id);
    }

}

When I try to access the property as follows I get an "DataPortal.Fetch failed on server" exception:

 

 

 

 

Business business = Business.GetBusiness(4);
Phones phones = business.Phones;

Here is the stack trace

   at lambda_method(Closure , Object , Object[] )
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Reflection\MethodCaller.cs:line 545
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Reflection\MethodCaller.cs:line 549
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Reflection\MethodCaller.cs:line 413
   at Csla.Reflection.LateBoundObject.CallMethod(String method) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Reflection\LateBoundObject.cs:line 77
   at Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Server\SimpleDataPortal.cs:line 129
   at Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Server\SimpleDataPortal.cs:line 158
   at Csla.Server.DataPortalSelector.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Server\DataPortalSelector.cs:line 87
   at Csla.Server.DataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\Server\DataPortal.cs:line 203
   at Csla.DataPortalClient.LocalProxy.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\DataPortalClient\LocalProxy.cs:line 49
   at Csla.DataPortal.Fetch(Type objectType, Object criteria) in C:\Development\CSLA .NET\4.1.0\Source\Source\Csla\DataPortal.cs:line 215

 

 

 

 

JonnyBee replied on Thursday, July 14, 2011

See the difference in your data portal calls?

 var creator = DataPortal.Fetch<PhoneListCreator>();
 return DataPortal.Fetch<PhoneListCreator>(id);

The first call has no parameter and the MethocCaller looks for DataPortal_Fetch() method with no args (and this obviously does not exeist in your code).

So I'd prefer to write the code as:

 public Phones Phones
{
    get
    {
        if(!FieldManager.FieldExists(PhonesProperty))
        {
          var creator = PhoneListCreator.GetPhoneListCreator(Id);
          Phones = creator.Result;
        }
        return ReadProperty(PhonesProperty);
    }
    private set
    {
      LoadProperty(PhonesProperty, value);
    }
}

 

hramos360 replied on Thursday, July 14, 2011

Thanks Jonny, that worked.

Copyright (c) Marimer LLC