views:

126

answers:

1

Consider a report in Windows forms which uses Linq to Objects as a datasource.

I have an entity named Loan with an association named Customer. The problem is that when I try to access the .Customer property in a report, it returns null or empty string.

I suppose this is because of lazy loading but I'm not sure to be honest. Is there a way to fix this issue?

A: 

In your case, closing the data context leads to null values for data that was not retrieved through a join. Use the DataLoadOptions to explicitely tell the context to perform a join:

using(var yourDataContext = .....)
{
    DataLoadOptions dlo = new DataLoadOptions();
    dlo.LoadWith<Loan>(loanRecord => loanRecord.Customers);
    yourDataContext.LoadOptions = dlo;
    //write code to retrieve data
}
lmsasu