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
|
Not sure if this is a bug - or user error... Am running the following query: var Custs = from C in db.Customersorderby C.CustomerName select new { CustomerID = C.Id, C.CustomerName, C.Address, C.Phone, C.Email, Jobs=C.Jobs.Count() }; And getting the following runtime error from the Count() on the foreign table: Unable to cast object of type 'System.Int64' to type 'System.Collections.Generic.IEnumerable`1[<>f__AnonymousType5`6 System.Int32,System.String,System.String,System.String,System.String,System.Int32]]'. Note this query worked okay in a previous build. |
|
|
It's a limitation. We can't currently perform a COUNT query within a SELECT query (and I'm therefore surprised to hear it worked in a previous build). You can get around this by writing C.Jobs.Count (note no brackets), but be aware that this will load the Jobs collection, which may be unacceptably inefficient depending on how many Jobs you expect and how big a Job object is (though you can optimise this using named aggregates). If that's a non-starter, you'll probably need to split it into two queries -- we can try to help with this if required. I'll flick your query over to Jeremy so that he can try to factor it into the LightSpeed 3 LINQ enhancements. |
|
|
I guess a more meaningful error message would have helped. It looked like something internal was returning an int64 and the generic was expecting an int32.
Thanks for the answer.
|
|