关于更新到Asp.Net Framework 4.5> LINQ to Entities仅支持转换EDM原语或枚举类型

时间:2014-09-26 15:19:31

标签: c# entity-framework linq-to-entities

以下代码一直有效,直到我转移到Asp.net Framework 4.5。

        var dateAndPort = (from c in context.CruiseCalendar
                        where c.ShipId == sourceId
                        && c.CruiseDayDate >= dateRange.Start
                        && c.CruiseDayDate <= dateRange.End
                        select new DateAndPort
                        {
                            Date = c.CruiseDayDate,
                            DestinationId = c.ListingId
                        });

        var shipRendezvous = (from r in context.CruiseCalendar
                             where (dateAndPort.Any(d => d.Date == r.CruiseDayDate
                             && d.DestinationId == r.ListingId))
                             select r).GroupBy(x => x.CruiseDayDate) //Groups by date
                            .Where(x => x.Count() >= shipCount) // if shipCount for dateAndPort > 0 only rendezvous will be returned
                            .SelectMany(x => x)
                            .OrderBy(r => r.CruiseDayDate)
                            .ToList();

          return shipRendezvous;

现在,这会在执行第二个查询时抛出错误(var shipRendezvous =)。错误已完整:

  

无法转换类型   &#39; {System.Linq.IQueryable {1}} 1 [[Seven.Domain.CustomTypes.DateAndPort,   Seven.Domain,Version = 1.0.0.0,Culture = neutral,   公钥=空]]&#39 ;. LINQ to Entities仅支持转换EDM   原始或枚举类型。

有什么想法吗?

(我用.ToList()贴了第一个查询,现在得到这个错误: 无法创建类型&#39; Seven.Domain.CustomTypes.DateAndPort&#39;的常量值。在此上下文中仅支持原始类型或枚举类型。)

0 个答案:

没有答案