için yeniden kullanılabilir LINQ parçalarının oluşturulması Daha fazla okunabilir hale getirmek için linq - sql sorgularını ayırmaya çalışıyorum.SQL
Önceki yıl içinde 100'den fazla siparişi olan tüm ürün siparişlerini iade etmek istiyorum.
private IQueryable<Order> LastSeasonOrders(Order order)
{
return (from o in _context.Orders
where o.Year == order.Year - 1 && o.Product == order.Product
select o);
}
sonra beni özgün sorgu için değiştirmenizi sağlar: Ben yapabilmek istiyorum ne
from o in _context.Orders
where (from o1 in _context.Orders
where o1.Year == o.Year - 1 && o1.Product == o.Product
select o1).Count() > 100
select o;
yeniden kullanılabilir bir işlevi iç içe sorgu koymaktır: Bu sorgu var:
from o in _context.Orders
where LastSeasonOrders(o).Count() > 100
select o;
Bu bir istisna sorgu çalıştırıldığında yöntem çağrısı SQL'e tercüme edilemez olduğunu söyleyerek ile ancak çalışmaz.
Bunu başarmak için doğru yollarla herhangi bir hızlı ipucu?
Bunu kendim merak ediyordum ama kendimi sormaya bile getiremedim. –