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 am getting a KeyNotFoundException from a query that returns no results I checked the query and it is valid and works in SQL Explorer The code was working when the query did return results SELECT
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Mindscape.LightSpeed.UnitOfWork.( ) at ..(AssociationModel ) at ..(TypeModel , QueryExpression , String , Boolean ) at ..(TypeModel , QueryExpression , Order , String , Boolean , Boolean ) at ..(TypeModel , IList , String , Boolean ) at ..(TypeModel , Query , IList ) at ..(UnitOfWork , TypeModel , Query , IList ) at ..(Query , TypeModel , IList ) at ..(Query , IList ) at Mindscape.LightSpeed.UnitOfWork.Find(Query query, IList results) at Mindscape.LightSpeed.UnitOfWorkBase.Find<TEntity>(Query query) System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, ref SignatureStruct sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Mindscape.LightSpeed.Linq.ProjectionStrategy.ExecuteEntityQuery(Query query, IUnitOfWork unitOfWork) at Mindscape.LightSpeed.Linq.ProjectionStrategy.Execute(Query query, IUnitOfWork unitOfWork) at Mindscape.LightSpeed.Linq.LinqQueryExecutionPlan.Execute() at Mindscape.LightSpeed.Linq.LinqQueryTranslator.Translate(Expression expression, IUnitOfWork unitOfWork, String viewName) 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.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList<TSource>(IEnumerable`1 source)
|
|
|
Here is the Linq that produced that query var material = from t in work.Materials It is an eager load query. I have two associations from Material to MartialDef. (MaterialDef and OriginalMaterialDef) If I set eager load on the MaterialDef association and then run the above query I get the above error when no items are returned from the query. |
|
|
This may have been caused by not having an association set up properly only having the BackReference and not the EntityCollection |
|
|
That sounds likely, though normally we would expect this to cause a "can't determine reverse association" error before you got to this stage. It sounds like you have this fixed, though if you still want us to look into it, then please send us the class definitions, the CREATE TABLE scripts and some sample data that reproduces the problem, and we'd be happy to do so. |
|