LINQ to Entities参数构造函数

时间:2015-12-22 18:21:30

标签: c# sql linq entity

我已经四处寻找多种解决方案,但似乎没有用。我的目标是使用LINQ查询来获取数据并填充对象;当我尝试将结果分配给ReponseObj时,我得到了

Only parameterless constructors and initializers are supported in LINQ to Entities.

ObjVO的构造函数是无参数的。

 public static ApiResponseObject<ObjVO> GetObjVO(int ID)
        {           
    ApiResponseObject<ObjVO> response = new ApiResponseObject<ObjVO>();
        Context ctx = new Context();
                        var myQuery = from cb in ctx.tblBlock
                                       join eve in ctx.tblEvent on cb.eventID equals eve.eventID
                                       where cb.BlockID == ID
                        select new ObjVO
                        {
                            Id = cb.BlockID,
                            Name = cb.BlockHeadline,
                            TotalTYProjectedSales = cb.totalTYProjectedSale.Value,
                            StoreTYProjectedSales = cb.storeTYProjectedSale.Value,
                            SiteTYProjectedSales = cb.storeTYProjectedSale.Value,
                            ModifiedBy = cb.LAST_UPD_USER_ID,
                            LastModifiedDate = cb.LAST_UPD_TS,
                            StoreUnitsOnHand = cb.storeUnitsOnHand.Value,
                            AssignedCutsCount = 0,
                            BlockHeadline = cb.contentBlockHeadline,
                            BelongsToLockedAd = false,
                            ProductLevel = 1,
                            SiteAvailability = false,
                        };

                        response.responseData = myQuery.FirstOrDefault();
}

1 个答案:

答案 0 :(得分:1)

这可能是因为EF无法将您的查询转换为SQL语句。

请参阅this以供参考。