编辑:删除了在ProductAttributes上包含仍然相同的结果表大小5万行的其他项
我得到了这段代码,与我的T-SQL语句相比,它运行得太慢了。
return _context.ProductAttributes
.Include(e => e.ProductProductAttributes)
.Select(x => new GetProductAttributesModel
{
Attribute = x,
Count = x.ProductProductAttributes.Count()
})
.ToArrayAsync();
以下是用于比较的T-SQL语句:
SELECT *
FROM Product_Attribute a
LEFT JOIN
(SELECT COUNT(*) AS ctn, AttributeId
FROM Product_ProductAttribute
GROUP BY AttributeId) d ON d.AttributeId = a.Id
如何获得更快或更至少类似于T-SQL语句的Entity Framework Core实现?
我希望我不需要为此选择一个存储过程...这看起来很简单
答案 0 :(得分:0)
好吧,社区达成共识,即实体不会为我提供此用例所需的速度。在这种情况下,我将选择一个存储过程。