本文介绍了如何使用linq将所选值分配到列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var result = (from r in db.Routes
join tin in db.TripIns on r.RouteId equals tin.RouteId
join tout in db.TripOuts on r.RouteId equals tout.RouteId
select new
{
RouteId = r.RouteId,
RouteName = r.RouteName,
RouteDesc = r.RouteDesc,
tripins = new TripIn{ TripInId = tin.TripInId, TripInName = tin.TripInName },
tripouts = new TripOut { TripOutId = tout.TripOutId, TripOutName = tout.TripOutName }
}).ToList()
.Select(x => new Route()
{
RouteId = x.RouteId,
RouteName = x.RouteName,
RouteDesc = x.RouteDesc,
TripIns = x.tripins,
TripOuts = x.tripouts
});
我的尝试:
What I have tried:
var result = (from r in db.Routes
join tin in db.TripIns on r.RouteId equals tin.RouteId
join tout in db.TripOuts on r.RouteId equals tout.RouteId
select new
{
RouteId = r.RouteId,
RouteName = r.RouteName,
RouteDesc = r.RouteDesc,
tripins = new TripIn{ TripInId = tin.TripInId, TripInName = tin.TripInName },
tripouts = new TripOut { TripOutId = tout.TripOutId, TripOutName = tout.TripOutName }
}).ToList()
.Select(x => new Route()
{
RouteId = x.RouteId,
RouteName = x.RouteName,
RouteDesc = x.RouteDesc,
TripIns = x.tripins,
TripOuts = x.tripouts
});
推荐答案
}).ToList()
.Select(x => new Route()
{
RouteId = x.RouteId,
RouteName = x.RouteName,
RouteDesc = x.RouteDesc,
TripIns = x.tripins,
TripOuts = x.tripouts
});
收件人:
To:
})
.Select(x => new Route()
{
RouteId = x.RouteId,
RouteName = x.RouteName,
RouteDesc = x.RouteDesc,
TripIns = x.tripins,
TripOuts = x.tripouts
}).ToList();
这篇关于如何使用linq将所选值分配到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!