简体   繁体   English

使用Linq合并多个字段

[英]Combining several fields using Linq

I'd like to combine several table fields in order to produce a combined value. 我想合并几个表字段以产生合并值。

Here's my code: 这是我的代码:

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

The showtime table includes the showID , startdate , starttime and endtime fields. showtime表包括showIDstartdatestarttimeendtime字段。

How can I select startdate and starttime in a field? 如何选择startdatestarttime在外地?

Something like this: 2015/12/12 12:25 -> 12:58 像这样: 2015/12/12 12:25 -> 12:58 : 2015/12/12 12:25 -> 12:58

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

If you wanna Keep your original Showtime object but just add that combined value, do something like the follwoing: 如果您想保留原始的Showtime对象,而只是添加该组合值,请执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM