IQueryable<PortServicesTariffDetail> detalis = _context.PortServicesTariffDetails
.Where(w => w.PortServicesTariffId == TariffId &&
w.PortServicesTariffDetailId == DetailId);
if (detalis.Count() > 0)
{
var mydetial = detalis.GroupBy(g => new { g.StartRate,g.EndRate }).AsQueryable();
_context.PortServicesTariffDetails.RemoveRange(mydetial.AsQueryable());
_context.SaveChanges();
}
取决于开始和结束费率删除范围,我提出了一些问题,如匿名类型。那我该怎么办?
参数1:无法从'System.Linq.IQueryable&gt;'转换到'System.Collections.Generic.IEnumerable'
答案 0 :(得分:1)
试试这个
foreach(var x in mydetial)
{
_context.PortServicesTariffDetails.RemoveRange(x.ToList());
}
_context.SaveChanges();
但是我不明白你为什么要把所有东西分组来删除它?
答案 1 :(得分:0)
试试这个:
var detalis = _context.PortServicesTariffDetails
.Where(w => w.PortServicesTariffId == TariffId &&
w.PortServicesTariffDetailId == DetailId).ToList();
if (detalis.Count() > 0)
{
var mydetial = detalis.GroupBy(g => new { g.StartRate,g.EndRate }).AsQueryable();
_context.PortServicesTariffDetails.RemoveRange(mydetial.AsQueryable());
_context.SaveChanges();
}
我认为没有必要使用Group by,
您只需使用RemoveRange
_context.PortServicesTariffDetails.RemoveRange(detalis);
_context.SaveChanges();