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
|
Works: var highRotateSongs = (from song in unitOfWork.ZslShowPlayLists where song.Show.Id == show.Id && song.HighRotateID == true select song.MasterPlayList).ToList(); Breaks: var highRotateSongs = (from song in unitOfWork.ZslShowPlayLists where song.Show.Id == show.Id && song.HighRotateID == true select new { Song = song.MasterPlayList }).ToList();
Type : System.InvalidCastException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Invalid cast from 'System.Int32' to 'Model.ZslMasterPlayList'. |
|
|
Fixed. The fix will be in the next nightly build. |
|
|
One other thing I noticed was that this query gets executed really inefficiently: var highRotateSongs = (from song in unitOfWork.ZslShowPlayLists where song.Show.Id == show.Id && song.HighRotateID == true select song.MasterPlayList).ToList() LightSpeed makes one query to ZslShowPlayLists and filters based on the show id and high rotate flag, selecting all columns (even though most aren't needed). LightSpeed then makes individual queries for each row returned in the first query to the MasterPlayList table using the MasterPlayListID and selecting all columns. It should be possible to do this LINQ query in one hit to the DB using an inner join. |
|
|
Hi Newt, We're looking at what we can do to optimize this scenario. For now, you should be able to do away with the N+1 by applying EagerLoad or a Named Aggregate through the MasterPlayList association. Let me know how you get on. Cheers Fishhooks. |
|