我正在尝试使用“GROUP BY”im MVC
这是我的功能
private readonly ICacheManager _cacheManager;
public virtual IList<ShippingByWeightRecord> GetAll()
{
string key = SHIPPINGBYWEIGHT_ALL_KEY;
return _cacheManager.Get(key, () =>
{
var query = from sbw in _sbwRepository.Table
group sbw by new
{
sbw.ShippingMethodId,
sbw.From,
sbw.To,
sbw.ShippingChargeAmount,
sbw.RegionId,
sbw.ItemRangeId
}
into grouping
select new { grouping.Key,
Id = grouping.Max(sbw => sbw.Id)
};
var records = query.ToList();
return records;
});
}
但是有错误。怎么做??这是我的 sql 命令。
SELECT MIN(Id) AS id, ShippingMethodId, [From], [To], ShippingChargeAmount, RegionId, ItemRangeId
FROM ShippingByWeight
GROUP BY ShippingMethodId, [From], [To], ShippingChargeAmount, RegionId, ItemRangeId
我想用 MVC 写它?你有什么主意吗???