Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to cast Anonymous Type from 'System.Linq.IQueryable' to 'System.Data.Entity.Core.Objects.ObjectQuery'
    primarykey
    data
    text
    <p>The following query was working well with EF5 but gives me error with EF6. I use DbContext and CodeFirst.</p> <p>Error raised with EF6:</p> <blockquote> <p>Unable to cast the type 'System.Linq.IQueryable<code>1[[&lt;&gt;f__AnonymousType5</code>4[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Wms.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=85d69d39f5becc93]]' to type 'System.Data.Entity.Core.Objects.ObjectQuery<code>1[[&lt;&gt;f__AnonymousType5</code>4[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Wms.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=85d69d39f5becc93]]'. LINQ to Entities only supports casting EDM primitive or enumeration types.</p> </blockquote> <p>Query (simplified):</p> <pre><code>var unitsPerPosition = context.Positions.Include(p =&gt; p.Unit).Select(x =&gt; new { Unit = x.Unit, Position = x }); var orders = ( from order in context.Orders.Include(x =&gt; x.SourceLocation); join unitPosition in unitsPerPosition on order.UnitId equals unitPosition.Unit.UnitId group new { order, unitPosition } by new { LocationId = order.SourceLocationId, Level = unitPosition.Position.Level } into groupOrders where groupOrders.Key.LocationId != null select new { LocationId = groupOrders.Key.LocationId.Value, Level = groupOrders.Key.Level, LoadingOrders = groupOrders.Count(), UnloadingOrders = -1 } ); IList&lt;LocationChannels&gt; searchResult = (from s in context.Locations .Include(s =&gt; s.Positions) .Include(s =&gt; s.Positions.Select(sp =&gt; sp.Unit)) let channels = from p in s.Positions where p.LocationId == s.LocationId group p by new { p.LocationId, p.Column, p.Level } into channelsGroup join order in orders on new { channelsGroup.Key.LocationId, channelsGroup.Key.Level } equals new { order.LocationId, order.Level } into ordersGroup from o in ordersGroup.DefaultIfEmpty() select new Channel { LocationId = channelsGroup.Key.LocationId, Column = channelsGroup.Key.Column, Level = channelsGroup.Key.Level } select new LocationChannels { Location = s, Channels = channels, }) .Where(predicate).ToList(); </code></pre> <p>The issue appears to be on the left join with the anonymous type loaded in variable 'orders'. I also tried to add a ToList() to the 'orders' query but then the error change to:</p> <blockquote> <p>Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context.</p> </blockquote> <p>Can someone gives me an hint on how to fix it?</p> <p><strong>UPDATE:</strong> The bug has been confirmed and resolved in EF 6.0.2. <a href="https://entityframework.codeplex.com/workitem/1751" rel="nofollow">See the Issue on CodePlex.</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload