使用Linq组合多个字段

本文关键字:字段 组合 Linq 使用 | 更新日期: 2023-09-27 17:53:28

我想合并几个表字段,以产生一个组合值。

下面是我的代码:

from _showtime in db.tbl_Concert_Showtime join _concerthall in db.tbl_Concert_ConcertHall on _showtime.ConcertHallID equals _concerthall.ConcertHallID
                 join _hall in db.tbl_Concert_Hall on _concerthall.HallID equals _hall.HallID
                 join _hallfloor in db.tbl_Concert_Hall_Floor on _hall.HallID equals _hallfloor.HallID
                 join _place in db.tbl_Concert_Hall_Floor_Place on _hallfloor.FloorID equals _place.FloorID
                 where _place.PlaceID == id
                 select _showtime

showtime表包含showIDstartdatestarttimeendtime字段。

如何在字段中选择startdatestarttime ?

像这样:2015/12/12 12:25 -> 12:58

使用Linq组合多个字段

from _showtime in db.tbl_blablabla    
select _showtime.startdate + " " + _showtime.starttime + " -> " + _showtime.enddate

如果你想保留原来的Showtime对象,但只添加组合值,请执行如下操作:

from _showtime in db.tbl_blablabla    
select new 
{
    Showtime = _Showtime, 
    CombinedValue = _showtime.startdate + " " + _showtime.starttime + " -> " + _showtime.enddate
}