私はそれを単一のクエリで書く必要があります。パラメータに応じて、regionidは、パラメータがゼロより大きい場合、regionidが条件のいずれかを保持する必要があります。このパラメータがリクエストに含まれている場合、含まれていない場合。
var myRegionId = 0;
if (!string.IsNullOrEmpty(regionId))
{
myRegionId = int.Parse(regionId);
}
IOrderedQueryable price;
if (myRegionId>0)
{
price = (from p in _db.PRICEs
join good in _db.GOODs on p.good_id equals good.id
join gname in _db.spr_goods_names on good.goods_name_id equals gname.id
where ******p.region_id == myRegionId &&** gname.name.ToLower().Contains(filterText.ToLower())****
group p by new{ p.good_id} into g
select new
{
GoodId = g.Key.good_id,
Promotion = g.Count(x => x.promotion != ""),
MinPrice = g.Min(x => x.good_price),
DistributorCount = g.Count(x => x.distributor_id != null)
}
).OrderByDescending(x => x.DistributorCount).Take(100).OrderBy(x => x.MinPrice);
}else
{
price = (from p in _db.PRICEs
join good in _db.GOODs on p.good_id equals good.id
join gname in _db.spr_goods_names on good.goods_name_id equals gname.id
**where gname.name.ToLower().Contains(filterText.ToLower())**
group p by new { p.good_id } into g
select new
{
GoodId = g.Key.good_id,
Promotion = g.Count(x => x.promotion != ""),
MinPrice = g.Min(x => x.good_price),
DistributorCount = g.Count(x => x.distributor_id != null)
}
).OrderByDescending(x => x.DistributorCount).Take(100).OrderBy(x => x.MinPrice);
}