This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I'm getting an exception thrown when executing the following query:
from organisation in Organisations select new {organisation.OrganisationName, organisation.Addresses} Addresses is a ThroughAssociation from Organisation to Address via OrganisationAddress.
NullReferenceException |
Object reference not set to an instance of an object. |
Message |
|
Object reference not set to an instance of an object. Data |
|
InnerException |
null |
StackTrace |
at ..€(IdentifierExpression , FieldModel& , ToOneModel& , & , String& ) |
at ..(IdentifierExpression , FieldModel& , ToOneModel& , & , String& ) at ..(IdentifierExpression ) at Mindscape.LightSpeed.Querying.IdentifierExpression.[T]( ) at ..(PathExpression ) at Mindscape.LightSpeed.Querying.PathExpression.[T]( ) at ..‚(QueryExpression ) at ..(QueryExpression ) at ..(AliasedTypeModel , QueryExpression , ProjectionCollection , Boolean , Boolean ) at ..(List`1 , Query , String , IdentifierExpression ) at ..(Query ) at Mindscape.LightSpeed.UnitOfWork.Project(Query query) at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ProjectNative(IUnitOfWork unitOfWork) at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteImmediate(IUnitOfWork unitOfWork, Type returnType) at Mindscape.LightSpeed.Linq.LinqQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQuery`1.System.Collections.IEnumerable.GetEnumerator() HelpLink |
null |
Source |
|
Mindscape.LightSpeed
|
|||
|
|
|
|
|
Btw, your upload attachment mechanism seems to be broken. I tried several times from both IE and Chrome and it just won't work, hence I've attached the diagram via URL. |
|
|
This simpler query will replicate the problem:
from organisation in Organisations select organisation.Addresses However, this query works:
from organisation in Organisations select organisation.Addresses.Select(address => address) I do need the former one to work though, and it should work. |
|
|
I've committed a fix which will prevent this error, and this will be included in nightly builds dated 6 Aug 2010 and above. However, LightSpeed does not truly support the use of through associations in projections. So the LINQ Select will be performed client-side, i.e. LightSpeed will select the organisations, then evaluate and return their Addresses collections. Consequently, the Organisation and OrganisationAddress entities will still be downloaded and materialised. To avoid a n+1 problem, make sure that the underlying associations of the through association are eager loaded. If you have fields in Organisation that are expensive to download (e.g. blobs), use a named aggregate to exclude those fields from the query. |
|