Lazy Loading w/WCF Portal Problem

Lazy Loading w/WCF Portal Problem

Old forum URL:

SomeGuy posted on Wednesday, March 03, 2010

I am running into a problem when I run my application with a WCF Portal.

I have a BO with Child and GrandChild BO's. I first ran into the problem with the GrandChild Objects, but double checked with just a Child Object.

Things work fine with a Local DataPortal, but when I try to use a WCF Portal, the lazy loaded Objects can't load. I am getting a NullReferenceException on the connection string. I have a Database class like the sample code that return ConfigurationManager.ConnectionStrings and it seems like it isn't reading the correct web.config file or something.

The WCF portal works fine for the Parent Object and Child Objects loaded in the Parent's Fetch, but the lazy loaded Objects fail.

Here's the Parent Object Child Property code:









Private static PropertyInfo<Images> ImagesProperty = RegisterProperty<Images>(p => p.Images);
public Images Images
if  (!(FieldManager.FieldExists(ImagesProperty)))
return GetProperty(ImagesProperty);

Here's the Child Object code:






Internal static Images GetImages(Project project)
return DataPortal.FetchChild<Images>(project.Id);


private void Child_Fetch(int projectId)
using (SqlConnection cn = new SqlConnection(Database.ProjectGalleryConnection))
using (SqlCommand cm = cn.CreateCommand())
cm.CommandType =
cm.CommandText =
"@projectId", projectId);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))

It's failing on the Database.ProjectGalleryConnection.

Any help is appreciated.


Marjon1 replied on Wednesday, March 03, 2010

I think the problem that you are having is because you are using DataPortal.FetchChild in the factory method for lazy loading.
The child dataportal methods work differently to what you would assume, and it was a mistake that I made as well.

Rocky explains it best in the this recent post:

SomeGuy replied on Wednesday, March 03, 2010

Thanks. I'll look into creating a Command object.


Copyright (c) Marimer LLC