我已经四处寻找多种解决方案,但似乎没有用。我的目标是使用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();
}