尝试如下:
var query1 = Db.ProductView.Where(w => w.DisplayFlag == "Y");
var paging = query1.Include(i => i.ProductImages).Select(s =>
new Products()
{
ProductCode = s.ProductCode,
DesignCode = s.DesignCode,
Code1 = s.Code1,
Code2 = s.Code2,
ProductImages = s.ProductImages.Where(i => (i.ImageNo == 1 & i.ImageType == "LS") ).Select(i => i),
ProductCoupons = Db.Database.SqlQuery<Coupon>("EXEC [USP_Front_EShop_Coupon_Select_By_ProductCode] @ProductCode", s.ProductCode)
}
);
但是,返回了以下错误:
* LINQ to Entities无法识别方法'System.Collections.Generic.IEnumerable`1 [Lesmore1.Models.Coupon SqlQuery [Coupon](System.String, System.Object [])'方法,此方法无法转换为商店表达式。 帮助我们了解出了什么问题..
答案 0 :(得分:1)
SqlQuery
会返回IEnumerable<T>
,这可能是您收到错误的原因。
尝试在调用.Single()
后获取.First()
或SqlQuery
以获取单个对象,或.Select()
或Where()
获取一系列对象。