This project is read-only.

Multiple calls to Select causes exception


I have written a Linq provider for the Google Base API and it mostly works very well. However, if I do a query like:

var q = context.GoogleProductItems.Select(p => new { p.Author, p.Description, p.Price }).Select(p => new { p.Author, p.Price })

An exception is thrown when I enumerate the query results. The exception detail is

System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Linq.Expressions.Expression1[System.Func2[CustomLinqProviderSample.GoogleProductItem,<>f__AnonymousType03[System.String,System.String,System.Decimal]]]' to type 'System.Linq.Expressions.Expression1[System.Func2[CustomLinqProviderSample.GoogleProductItem,<>f__AnonymousType12[System.String,System.Decimal]]]'."
   at LinqExtender.ProjectedQuery`2.ProcessGenericList() in C:\Source\Sage 200 Architecture Team\TFS Projects\Mikes Projects\New Linq.Google\Linq Extender\ProjectedQuery.cs:line 49
   at LinqExtender.ProjectedQuery`2.GetEnumerator() in C:\Source\New Linq.Google\Linq Extender\ProjectedQuery.cs:line 36
   at GoogleTestConsole.Program.Main(String[] args) in C:\Source\New Linq.Google\GoogleTestConcole\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

The problem I think is that QueryExtension.GetUnaryExpressionFromMethodCall is not properly resolving the expression. It ends up returning the lambda expression from the first call to Select. The body of this expression is AnonymousType0 <string, string, decimal> whereas the second type argument for the ProjectedQuery<T,S> is AnonymousType1 <string, decimal>


mehfuzh wrote Jan 6, 2010 at 6:40 PM

Good catch, will fix it. Actually creating a new version. So wait till end of this week/early next week.

theblacklabrador wrote Mar 11, 2010 at 2:31 PM


Is there any progress on this? It might seem obscure, but it's actually a critical bug for my project!

Any updates welcome!


mehfuzh wrote Mar 11, 2010 at 7:59 PM

Hi Sorry for being late,
I will try it and come back to you in a day or two.