LINQ to Entities中不支持“指定的类型成员”但是在LINQPad中工作

时间:2016-11-30 13:38:47

标签: entity-framework

我有一个名为DashboardGroupData的类

public class DashboardGroupData
{
    public int ConsignmentID {get;set;}
    public DateTime ActualManifestDate {get;set;}
    public DateTime PlannedLatestDeliveryDateTime {get;set;}
    public DateTime PlannedEarliestDeliveryDateTime {get;set;}
    public DateTime PlannedEarliestCollectionDateTime { get; set; }
    public string Status {get;set;}
    public int ServiceLevelID {get;set;}
    public double PalletWeight {get;set;}
    public int MaxMove {get;set;}
    public int LastMove { get; set; }
    public int PalletStatusID { get; set; }
    public int Sequence { get; set; }
    public int RequestDepotID { get; set; }
    public int CollectionDepotID { get; set; }
    public bool Collection { get; set; }
}

我有以下实体查询:

                        groupConsignmentList = (from d in connectDB.vwDepotDashboards
                                            where depotAndSubDepots.Contains(d.DeliveryDepotID)
                                            && !incomplete.Contains(d.Status)
                                            && (!depotAndSubDepots.Contains(d.CollectionDepotID) || d.CustDirectToHub)
                                            && d.Sequence < (int)PalletStatusSequence.ICC
                                            && d.ActualManifestDate > validWindow
                                            && d.TransitHubID == hubID
                                            select new Models.DashboardGroupData()
                                            {
                                                ConsignmentID = d.ConsignmentID,
                                                ActualManifestDate = d.ActualManifestDate,
                                                PlannedLatestDeliveryDateTime = d.PlannedLatestDeliveryDateTime,
                                                PlannedEarliestDeliveryDateTime = d.PlannedEarliestDeliveryDateTime,
                                                Status = d.Status,
                                                PlannedEarliestCollectionDateTime = d.PlannedEarliestCollectionDateTime,
                                                ServiceLevelID = d.ServiceLevelID,
                                                PalletWeight = d.PalletWeight,
                                                PalletStatusID = d.PalletStatusID,
                                                Sequence = d.Sequence,
                                                Collection = d.Collection,
                                                RequestDepotID = d.RequestDepotID,
                                                MaxMove = connectDB.PalletMovements.Where(c => c.CreatedDateTime < manifestDayEnd && c.PalletID == d.PalletID && !(c.PalletMovementTypeID > 12 && c.PalletMovementTypeID < 19)).Max(c => (int?)c.PalletMovementTypeID) ?? 0
                                            });

当我尝试进一步查询(如下)时,我得到“LINQ to Entities中不支持指定的类型成员。仅支持初始化程序,实体成员和实体导航属性”错误:

var test = groupConsignmentList.Where(c => c.Sequence > 650  && c.Sequence < 1000).Select(c => c.ConsignmentID).ToList();

直接编写为SQL查询的相同查询与LINQPad 5中的上述查询完全一样,使用与应用程序相同的连接和实体模型。

我已经尝试将数据库中的字段序列重命名为不是SQL保留字的字段 - 但它没有任何区别。

一个线索:如果我接受第一个查询(“groupConsignmentList =”)并将其转换为列表,则在列表的每个成员中,Sequence的值为零 - 而在LINQPad 5中,它会生成正确的值。 / p>

.Net框架是4.6

1 个答案:

答案 0 :(得分:0)

问题在于我没有意识到代码中对groupConsignmentList的查询分配不止一个 - 而且我添加了Sequence的那个不是在这种情况下使用的那个。