我有这个问题:
var ftr_dist = db.DIST_VIEW.Where(x => x.CITY == "Los Angeles");
var mst2 = db.TB_SERVICE.Where(x => x.ID == x.ID);
var trf2 = db.TYPE.Where(x => x.ID == x.ID);
var Data = (from ftr in ftr_dist
join mst in mst2 on ftr.CUSTOMER_ID equals mst.CUSTOMER_ID
join trf in trf2 on mst.TYPE_ID equals trf.ID
select new TypeObj { City = ftr.CITY, County = ftr.COUNTY, Type = trf.Type }
).OrderBy(i => i.City).ThenBy(i => i.County).ToList();
ftr_dist有大约72000行。 mst2有1100000行,trf2有340行。但是获取数据需要很长时间。如何更快地进行此查询?感谢。
答案 0 :(得分:0)
您实际上是在执行4种不同的查询。查询确实需要比sql字符串更长的查询...尝试使用Linq。将所有查询合并为一个。
我对你的lambda查询(x => x.ID == x.ID)有点困惑。您可能需要将其添加到下面的
var data = from ftr in db.DIST_VIEW
join mst in db.TB_SERVICE on ftr.CUSTOMER_ID equals
mst.CUSTOMER_ID
join trf in db.TYPE on trf.TYPE_ID equals ftr.ID
where ftr.CITY == "Los Angeles"
select new TypeObj
{
City = ftr.City,
Country = ftr.County,
Type - trf.Type
}.OrderBy(i => i.City).ThenBy(i => i.County).ToList();